Code

Opened 7 years ago

Closed 7 years ago

#4997 closed (wontfix)

[patch] Add group_by() support to QuerySets

Reported by: David Cramer <dcramer@…> Owned by: adrian
Component: Database layer (models, ORM) Version: master
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: UI/UX:

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@…> 7 years ago.
models.py (1.4 KB) - added by David Cramer <dcramer@…> 7 years ago.
tests/regressiontests/group_by/models.py

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by David Cramer <dcramer@…>

Changed 7 years ago by David Cramer <dcramer@…>

tests/regressiontests/group_by/models.py

comment:1 Changed 7 years ago by anonymous

  • Cc bharring@… added
  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by russellm

  • Resolution set to wontfix
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.