Hello,
Today I've commited what could be called the first working version of
aggregate support. For those of you not keeping track of  the project,
it can be found at: http://code.google.com/p/django-aggregation/

Some words on the status of the project.

Working
------------
 * Currently both annotate() and aggregate() queryset modifiers are
available.
 * aggregate() is a terminal clause and returns a dictionary.
 * annotate() returns a queryset. By default objects are grouped by
all the fields in the model.
 * 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
 * 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 doctests.
 * The related fields can now be refered to implicitly ( Count('book')
instead of Count('book__id') )

Not Working (yet)
-----------------------
 * The way of creating/extending aggregate functions is very basic.
More work is needed to make it easy to create new functions or modify
the existing ones. (there is no syntax or API defined for that yet)
 * There is, still, no way of expressing subqueries or aggregating on
annotated fields.

Not Tested
---------------
 * Model Inheritance

Extra
-------
 I don't want to close this message without mentioning a new feature
that has not been discussed in the mailing list. Now when doing an
annotate call on a ValuesQuerySet (i.e. grouping on only some fields
of the model) there is an extra parameter for every object called
"group" that contains a QuerySet for retreiving the objects that have
been grouped to do the aggregation.
So:
>>> books = Book.objects.values('price').annotate(oldest=Max('authors__age'))
>>> books[0].get('price')
29.690000000000001
>>> books[0].get('group')
[<Book: Practical Django Projects>, <Book: Python Web Development with
Django>]
>>> books
[
 {'price': 29.690000000000001, 'oldest': 37.0, 'group': [<Book:
Practical Django Projects>, <Book: Python Web Development with
Django>]},
 {'price': 75.0, 'oldest': 57.0, 'group': [<Book: Paradigms of
Artificial Intelligence Programming: Case Studies in Common Lisp>]},
 {'price': 82.799999999999997, 'oldest': 57.0, 'group': [<Book:
Artificial Intelligence: A Modern Approach>]},
 {'price': 23.09, 'oldest': 45.0, 'group': [<Book: Sams Teach Yourself
Django in 24 Hours>]},
 {'price': 30.0, 'oldest': 35.0, 'group': [<Book:  The Definitive
Guide to Django: Web Development Done Right>]}
]
(Yes, the querysets are lazyly evaluated)

I hope you all like this feature. I know I do.

Now I am going to spend some time documenting the current state before
moving onto the rest of the issues/features. I any of you can take a
look at it and play around to see if it fits your need it would be
great. Also if you have any problems, complains, feature requests,
suggestions, discussions to be made in the mailing list... please let
me know =)

Cheers,

Nicolas Lara
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to