0

I'm trying to output a conditional sum / aggregation via django in html. Though not sure what to put in my template?

see below :

in views.py: (part of my code )

total_paid = CF.objects.filter(type='Payment').aggregate(Sum('amount')
return render(request, 'budget/budget_detail.html', {'paid': total_paid })

in budget/budget.html :

{{ paid }} 

output is as follows in my browser : {'amount__sum': Decimal('-1500')}

can anyone help me? thanks !!

TMD
  • 191
  • 1
  • 2
  • 14

1 Answers1

1

You're looking for

 {{ paid.amount__sum }}

Although you may just want to provide a key for the sum in your aggregation to make it a nicer variable name

...aggregate(total=Sum('amount'))
{{ paid.total }}
Sayse
  • 42,633
  • 14
  • 77
  • 146