Opened 11 years ago

Closed 9 years ago

Last modified 7 years ago

#10972 closed New feature (duplicate)

Use Expressions with Annotations

Reported by: me@… Owned by:
Component: Database layer (models, ORM) Version: master
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 Ramiro Morales)

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 Changed 11 years ago by anonymous

Version: 1.1-beta-1SVN

comment:2 Changed 11 years ago by Ramiro Morales

milestone: 1.1

comment:3 Changed 11 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:4 Changed 11 years ago by django@…

Cc: django@… added

comment:5 Changed 11 years ago by Alexander Koshelev

Cc: Alexander Koshelev added

comment:6 Changed 11 years ago by miracle2k

Cc: miracle2k added

comment:7 Changed 11 years ago by miracle2k

Has patch: set

I've written a basic patch enabling this, against the current trunk:

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):

Generally though, it seems to work. Maybe this can inspire someone to do a better implementation. A set of simple tests included.

comment:8 Changed 11 years ago by meticulos_slacker

Cc: meticulos_slacker added

comment:9 Changed 10 years ago by anonymous

Cc: bgrand added

comment:10 Changed 10 years ago by nwp

Cc: nwp added
Patch needs improvement: set

comment:11 Changed 9 years ago by Dan Fairs

Cc: Dan Fairs added

comment:12 Changed 9 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:13 Changed 9 years ago by Ramiro Morales

Description: modified (diff)
Easy pickings: unset
UI/UX: unset

comment:14 Changed 9 years ago by Ramiro Morales

Resolution: duplicate
Status: newclosed

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 Changed 7 years ago by Anssi Kääriäinen

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top