django/django — pull request #2184 by jarshwah (2014-01-19 12:56:57+00:00)
Title: Refactor aggregates as expressions

This PR isn't ready for commit, and is not complete, but I'm hoping for some feedback on the direction.

The patch is in reference to: https://code.djangoproject.com/ticket/14030 and currently implements aggregates as ExpressionNodes (F() objects), allowing behaviour like:

```Author.objects.annotate(combined_ages=Sum(F('age')+F('friends__age')))```

There's still a bit that needs to be done:

- Fix some issues relating to Lookups and GIS
- Figure out a decent strategy for exposing attributes like is_aggregate to a combined expression
- Validating aggregates that have specific backend requirements (like sqlite or GIS limitations)
- Some general tidying up
- Implement non-aggregate annotations (or this could be done in a separate branch)

I'd love to hear some feedback, especially from maintainers of 3rd party backends (SQL and NoSQL). I'm aiming for as much backwards compatibility as possible, so please raise any pain points.

Previous discussion on the mailing list: https://groups.google.com/forum/#!topic/django-developers/8vEAwSwJGMc