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

▼魔方 西西 提交于 2019-11-29 05:32:22

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.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!