Opened 13 years ago

Closed 13 years ago

#16775 closed New feature (duplicate)

Support for simple arithmetic in ORM annotations

Reported by: Dan Loewenherz Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I would like to use the Django ORM to run a query such as the following:

SELECT SUM(amount * quantity) FROM orders;

Right now, I'm not sure this is possible. As for a potential API, I might suggest something like this:

Order.objects.annotate(sum=Sum(F("amount") * F("quantity")))

Thoughts? Suggestions?

Change History (1)

comment:1 by Ramiro Morales, 13 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #14030.

Note: See TracTickets for help on using tickets.
Back to Top