Opened 17 years ago
Closed 17 years ago
#4997 closed (wontfix)
[patch] Add group_by() support to QuerySets
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | group_by, orm | |
Cc: | bharring@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The following adds the ability to do .group_by() on QuerySet objects.
# Should return one result unique to each foreignkey
MyModel.objects.all().group_by('foreignkey')
# Returns the numbers of results available. Calls a DISTINCT() query on group_by fields
MyModel.objects.all().group_by('foreignkey').count()
Attachments (2)
Change History (4)
by , 17 years ago
Attachment: | query.py.diff added |
---|
by , 17 years ago
comment:1 by , 17 years ago
Cc: | added |
---|---|
Needs documentation: | set |
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The idea of a 'group_by' and 'having' clause has been floated many times before, and has been rejected in preference of an 'aggregations' framework that provides a higher level, ORM-like interface (rather than a SQL like interface) to the the ideas that group_by and having expose. See Ticket #3566 for details on current thinking.
Adding this feature is waiting on a refactor of the internals of the query engine. Malcolm is in the process of doing this refactor; any patch against query.py is likely to be rendered invalid in the near future.
tests/regressiontests/group_by/models.py