So, I am making a django application for an expense schedule, and I am stuck trying to display the sum of all inputted costs.
I created a user manager to calculate the amount:
class ExpenseManager(models.Manager): def price_sum(self): return super(ExpenseManager, self).aggregate(total_price = Sum('price'))['total_price']
And added it to my model:
class Expense(models.Model): ... objects = models.Manager() price_object = ExpenseManager() ...
I know that my manager works because when I execute it in the shell I get the correct amount of my expenses, that is, I put in Expense.price_object.price_sum() and I return Decimal('254.77') - but when I am trying to get this in my template just showing empty.
I tried putting several different methods into my variable, but none of them worked, for example:
{{price_object.price_sum}}
or
{{expense.price_object.price_sum}}
or me desperately ...
{% for p in expense.price_object %} {{p.price_sum}} {% endfor %}
or
{% for p in expense.price_object.price_sum %} {{p}} {% endfor %}
but yes ... nothing appears when I load the page. Can anyone help?
source share