#10972 closed New feature (duplicate)
Use Expressions with Annotations
Reported by: | Owned by: | ||
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | expression aggregation aggregates annotation |
Cc: | samt@…, django@…, Alexander Koshelev, miracle2k, meticulos_slacker, bgrand, nwp, Dan Fairs | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
It would be nice if expressions could be used inside annotations, i.e. to perform something like the following:
Customer.objects.annotate('total_purchased': Sum(F('customer__order__lineitem__quantity') * F('customer__order__lineitem__price')))
Change History (15)
comment:1 by , 16 years ago
Version: | 1.1-beta-1 → SVN |
---|
comment:2 by , 16 years ago
milestone: | 1.1 |
---|
comment:3 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 15 years ago
Cc: | added |
---|
comment:5 by , 15 years ago
Cc: | added |
---|
comment:6 by , 15 years ago
Cc: | added |
---|
comment:7 by , 15 years ago
Has patch: | set |
---|
comment:8 by , 15 years ago
Cc: | added |
---|
comment:9 by , 14 years ago
Cc: | added |
---|
comment:10 by , 14 years ago
Cc: | added |
---|---|
Patch needs improvement: | set |
comment:11 by , 14 years ago
Cc: | added |
---|
comment:12 by , 13 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:13 by , 13 years ago
Description: | modified (diff) |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:14 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I'm closing this as a duplicate of #14030 because although this ticker is older, the other one has a wider scope as shown by its Summary and has a comment by a cor developer.
comment:15 by , 12 years ago
Component: | ORM aggregation → Database layer (models, ORM) |
---|
Note:
See TracTickets
for help on using tickets.
I've written a basic patch enabling this, against the current trunk:
http://github.com/miracle2k/django/tree/10972-aggrating-expr
There are some things I had trouble with, where I'm definitely not sure what the right thing do to is, for example the way the Where node now needs to handle children who's as_sql() returns a 2-tuple (sql, params):
http://github.com/miracle2k/django/commit/13b0e62772557ad54cd0b51b551ad230784e7eb1#L6L152
Generally though, it seems to work. Maybe this can inspire someone to do a better implementation. A set of simple tests included.