I am writing to let you know that I have posted the latest patches on
aggregation support. All the planned features are implemented in the
patch for #3566.
For those not keping trac these are:
* Two queryset modifiers for doing aggregation: aggregate() and annotate().
* aggregate() is a terminal clause and returns a dictionary.
* annotate() returns a queryset and each object is extended with
the aggregation information. By default objects are grouped by all the
fields in the model.
* There are aggregate objects for representing the aggregation
functions to be used. Aggregate objects for the main SQL aggregation
functions are available.
* Count aggregate object takes an extra parameter 'distinct' that
translates into the sql: COUNT(DISTINCT field)
* It is possible to define custom grouping by calling
values('fields', 'to', 'group', 'by') before doing an annotate() call.
This will result in a group by call at the backend level.
* Aliases for the aggregations are generated automatically when
not explicitly provided.
* Filtering on aggregated values is possible. It results in a
HAVING sql clause. There are some interesting cases of filtering that
can be found in the documentation and tests.
* Ordering on aggregates is allowed.
* In MySQL: When not specifying grouping explicitly on annotate
the grouping is made only by the pk and not all the fields.
* Doing annotate().aggregate() does aggregation on the previous query.
* When grouping an extra parameter is available to get the result
along with a queryset to retrieve the objects that were grouped.
There is also a patch posing a re-write of #7210 to remove the
dependency on the model so it would be easy to have aggregates (and
columns selected via extra() ) working with F objects.
All that's left now is a bit of community testing. I'll keep the
patches updated and be aware of any bug that might arise to try and
fix it as soon as possible.
Best Regards =),
--
Nicolas Lara
I would just like to take this opportunity to thank Nicolas for his
hard work. Aggregates have been a long standing feature request for
Django, so it's great to be able to finally be in a position to be
able to close the ticket.
For those looking out for aggregates in trunk - my goal is to start
integrating this once the dust has settled (and the hangovers have
subsided) on v1.0.
Again, great work Nicolas. I hope you hang around the Django community
and contribute more great work like this.
Russ Magee %-)