Opened 4 years ago

Closed 4 years ago

#16775 closed New feature (duplicate)

Support for simple arithmetic in ORM annotations

Reported by: dloewenherz 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


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 Changed 4 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #14030.

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