Django

Code

Ticket #4997 (closed: wontfix)

Opened 3 years ago

Last modified 3 years ago

[patch] Add group_by() support to QuerySets

Reported by: David Cramer <dcramer@gmail.com> Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: group_by, orm
Cc: bharring@curse-gaming.com Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 1
Needs tests: 0 Patch needs improvement: 0

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

query.py.diff (4.2 kB) - added by David Cramer <dcramer@gmail.com> on 07/27/07 21:44:57.
models.py (1.4 kB) - added by David Cramer <dcramer@gmail.com> on 07/27/07 21:45:40.
tests/regressiontests/group_by/models.py

Change History

07/27/07 21:44:57 changed by David Cramer <dcramer@gmail.com>

  • attachment query.py.diff added.

07/27/07 21:45:40 changed by David Cramer <dcramer@gmail.com>

  • attachment models.py added.

tests/regressiontests/group_by/models.py

07/27/07 21:48:00 changed by anonymous

  • cc set to bharring@curse-gaming.com.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs set to 1.

07/27/07 22:06:02 changed by russellm

  • status changed from new to closed.
  • resolution set to wontfix.

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/Change #4997 ([patch] Add group_by() support to QuerySets)




Change Properties
Action