Code

Opened 2 years ago

Closed 23 months 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.

Attachments (0)

Change History (3)

comment:1 Changed 2 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 2 years ago by mbertheau@…

  • Cc mbertheau@… added

comment:3 Changed 23 months 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.

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.