I want to get the row wise sum of all previous value in column amount.
models.py
class PaymentRecord(models.Model):
invoice_no = models.ForeignKey(Invoice, unique=False, related_name='paymentrecord', on_delete=models.CASCADE)
amount = models.CharField(max_length=10)
paid_into = models.CharField(max_length=40, choices=PAID)
payment_date = models.DateField(auto_now=False, auto_now_add=False)
cheque_date = models.DateField(auto_now=False, auto_now_add=False, null=True, blank=True)
cheque_no = models.CharField(max_length=20, null=True, blank=True)
notes = models.CharField(max_length=100, null=True, blank=True)
I tried the queryset
pay_receipt = PaymentRecord.objects.filter(Q(payment_date__range=[startdate, enddate]),Q(paid_into='ONLINE') | Q(paid_into='CHEQUE')).annotate(totals=Sum('amount')).order_by('payment_date')
I want the result like this
Id paid_into payment_date amount SumAmount
---------------------------------------------------------
1 ONLINE 12-09-2019 40.00 40.00
2 ONLINE 12-09-2019 40.00 80.00
3 ONLINE 12-09-2019 45.00 125.00
4 ONLINE 12-09-2019 50.00 175.00