Opened 17 years ago

Closed 17 years ago

#4997 closed (wontfix)

[patch] Add group_by() support to QuerySets

Reported by: David Cramer <dcramer@…> 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)

query.py.diff (4.2 KB ) - added by David Cramer <dcramer@…> 17 years ago.
models.py (1.4 KB ) - added by David Cramer <dcramer@…> 17 years ago.
tests/regressiontests/group_by/models.py

Download all attachments as: .zip

Change History (4)

by David Cramer <dcramer@…>, 17 years ago

Attachment: query.py.diff added

by David Cramer <dcramer@…>, 17 years ago

Attachment: models.py added

tests/regressiontests/group_by/models.py

comment:1 by anonymous, 17 years ago

Cc: bharring@… added
Needs documentation: set

comment:2 by Russell Keith-Magee, 17 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top