[Django]-Django – Can you use property as the field in an aggregation function?

29👍

No. Anything that goes through a built-in manager has to be a real field, since they only touch the database. In order to work with a property they’d have to turn every record in the table into a model, then filter through them in Python.

5👍

I have a similar scenario and want exactly the same feature. I solved it trivially with the following line:

...
return sum(lt.cost for lt in self.lineitem_set)

0👍

Leave a comment