1๐
โ
I think you could try one of this:
-
Sum inside the for loop
total = 0 for obj in dataangsuran: total = total + obj.cangsuranpokok col = [ str(obj.ckarid), str(obj.ckarid.cnik_nip), total, str(obj.cangsuranpokok), ]
And then use total
-
Take the sum from ORM
from django.db.models import Sum dataangsuran.aggregate(total=Sum('cangsuranpokok'))
Keep in mind that dataangsuran
is a QuerySet
object, so you can add the aggregate
after the first loop, when you write the excel file.
๐คGocht
Source:stackexchange.com