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?
Note:
See TracTickets
for help on using tickets.
Duplicate of #14030.