I have daily transaction datas, and has multiple mode of payments.
I wish I can sum by mode of payment and group it by months.
I have uploaded an image file, what I want to achive.
Below are my view and template
def bymonth(request):
ms = {
'monjc': Daily.objects.aggregate(mjc=Sum('transamount',
filter=Q(transdate__month=1) & Q(transmode__name='Cash')))['mjc'],
'monfc': Daily.objects.aggregate(mfc=Sum('transamount',
filter=Q(transdate__month=2) & Q(transmode__name='Cash')))['mfc'],
'monje': Daily.objects.aggregate(mje=Sum('transamount',
filter=Q(transdate__month=1) & Q(transmode__name='ENBD')))['mje'],
'monfe': Daily.objects.aggregate(mfe=Sum('transamount',
filter=Q(transdate__month=2) & Q(transmode__name='ENBD')))['mfe'],
}
return render(request, 'bymonth.html', ms)
<table border="1">
<tr>
<td></td>
<td>Jan</td>
<td>Feb</td>
<td>Mar</td>
<td>Apr</td>
<td>May</td>
<td>Jun</td>
<td>Jul</td>
<td>Aug</td>
<td>Sep</td>
<td>Oct</td>
<td>Nov</td>
<td>Dec</td>
</tr>
<tr>
<td>Cash</td>
<td>{{ monjc | floatformat:'2g' }}</td>
<td>{{ monfc | floatformat:'2g' }}</td>
</tr>
<tr>
<td>ENBD</td>
<td>{{ monje | floatformat:'2g' }}</td>
<td>{{ monfe | floatformat:'2g' }}</td>
</tr>
<tr>
<td>NoL</td>
</tr>
<tr>
<td>Pay IT</td>
</tr>
<tr>
<td>SIB</td>
</table>
In the template I want to have the months only which are available in the data.
For Example: I have datas only upto this month ( May )
It will be growing daily, wish to have dynamic displaying of months in the template.
Please guide.
And my current output is as below, help me to improve