Opened 4 years ago

Closed 4 years ago

#17839 closed New feature (wontfix)

Ordering by an expression containing annotations

Reported by: joseph.helfer@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: mbertheau@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have found a query use case which seems not to be covered by query() and extra().
I have two annotations: .annotate(x=Count('foo')) and .annotate(y=Count('bar')) and I want to do something like
This (as written) doesn't work, however, because order_by only takes strings.
Another solution would be to use .extra(select={z: 'x + y'}) and then .extra(order_by=['z']), but that doesn't work either, because extra can't refer to annotations.

Change History (3)

comment:1 Changed 4 years ago by joseph.helfer@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The first line of the description should read:
I have found a query use case which seems not to be covered by F() and extra().

comment:2 Changed 4 years ago by mbertheau@…

  • Cc mbertheau@… added

comment:3 Changed 4 years ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

The ORM doesn't intend to cover 100% of what you may want to do with your database. In this case, it sounds more reasonable to switch to raw SQL.

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