Opened 14 years ago
Closed 14 years ago
#17839 closed New feature (wontfix)
Ordering by an expression containing annotations
| Reported by: | 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 , 14 years ago
comment:2 by , 14 years ago
| Cc: | added |
|---|
comment:3 by , 14 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → 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.
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().