Opened 13 years ago

Closed 12 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

Description

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
.order_by(F('x')+F('y')).
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 by joseph.helfer@…, 13 years ago

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 by mbertheau@…, 13 years ago

Cc: mbertheau@… added

comment:3 by Aymeric Augustin, 12 years ago

Resolution: wontfix
Status: newclosed

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