how to use reverse query data from a child model to do arithmetic's in parent model?

11 views
Skip to first unread message

Vansh Jagyasi -IIITK

unread,
Mar 28, 2021, 10:05:15 AM3/28/21
to Django users
I have created a model location, and a model transaction which has a many to one relation with location which has the information of a transaction done at a particular location, say 3 dollars spent at macdonalds, now I want to find all the transactions related to a particular location and add the amount to find the total amount spent,please help

models.py

Ryan Nowakowski

unread,
Mar 28, 2021, 12:09:51 PM3/28/21
to django...@googlegroups.com
You probably want to use `Sum` from Django aggregate:

https://docs.djangoproject.com/en/3.1/topics/db/aggregation/
Reply all
Reply to author
Forward
0 new messages