Django Aggregation: Summation of Multiplication of two fields
问题 I have a model something like this: class Task(models.Model): progress = models.PositiveIntegerField() estimated_days = models.PositiveIntegerField() Now I would like to do a calculation Sum(progress * estimated_days) on the database level. Using Django Aggregation I can have the sum for each field but not the summation of multiplication of fields. 回答1: Update: for Django >= 1.8 please follow the answer provided by @kmmbvnr it's possible using Django ORM: here's what you should do: from