#25534: Allow using datetime lookups in QuerySets aggregate calls
-------------------------------------+-------------------------------------
Reporter: borfast | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):
* keywords: QuerySet.extra =>
* version: 1.7 => master
* stage: Unreviewed => Accepted
Comment:
It's not a duplicate, no, but they are related. #10302 wants
transform/lookup support in `values()` whereas this ticket is asking for
support in aggregates/expressions.
1.9 converts transforms into func expressions, so we'll be able to do
something like (simplifying the model here..):
{{{
from django.db.models.lookups import MonthTransform as Month
result =
ElectricityReading.objects.aggregate(total=Count(Month('datetime')))
}}}
Which isn't quite as nice as `Count('datetime__month')`. It should be
possible to convert the latter into the former internally though. I would
imagine this would be handled internally within `F()`. Detect if we're
trying to access a transform, extract the transform, wrap the original
field, and continue as normal. This example (datetime part extraction) is
probably the canonical usecase for __transform support in aggregates.
If transforms can be supported with underscore syntax within `F()`
objects, then that should solve #10302 as well. There are probably a few
more tickets that could be closed with this implementation.
--
Ticket URL: <https://code.djangoproject.com/ticket/25534#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.4d371c212660e34626adf351eae86987%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.