def testing(request):
totals_dict = {
'Eating': Daily.objects.aggregate(eats=Sum('transamount', filter=Q(transcategory_id=5) & Q(transdate__month=1) | Q(transcategory_id=19) & Q(transdate__month=1) | Q(transcategory_id=20) & Q(transdate__month=1) | Q(transcategory_id=28) & Q(transdate__month=1) | Q(transcategory_id=31) & Q(transdate__month=1)))['eats'],
'Trans_List': Daily.objects.all(),
'Total_Bal': Daily.objects.all().aggregate(tb=Sum('transamount'))['tb'],
'Cash_Bal': Daily.objects.aggregate(CashBAL=Sum('transamount', filter=Q(transmode__name='Cash')))['CashBAL'],
'Enbd_Bal': Daily.objects.aggregate(ENBDBAL=Sum('transamount', filter=Q(transmode__name='ENBD')))['ENBDBAL'],
'NoL_Bal': Daily.objects.aggregate(NoLBAL=Sum('transamount', filter=Q(transmode__name='NoL')))['NoLBAL'],
'PayIT_Bal': Daily.objects.aggregate(PayITBAL=Sum('transamount', filter=Q(transmode__name='Pay IT')))[
'PayITBAL'],
'Sib_Bal': Daily.objects.aggregate(SibBAL=Sum('transamount', filter=Q(transmode__name='SIB')))['SibBAL'],
}
return render(request, 'testing.html', totals_dict)
In my above ‘view’, I am getting correct result for ‘Eating’ but I have hardcoded the month as ‘1’, so it’s 'Sum’ming only for January.
Please guide me to make every ‘Sum’ based on months.
Is it possible to create the dict values inside a loop like
"for i in 1 to 12 "