class Tip(models.Model):
prediction = models.ForeignKey(Prediction, on_delete=models.CASCADE)
pl = models.DecimalField(decimal_places=3, max_digits=5, default=None, blank=True, null=True)
class Prediction(models.Model):
fixture = models.ForeignKey(to=Fixture, on_delete=models.CASCADE, related_name="predictions", null=True, blank=True)
class Fixture(models.Model):
date = models.DateTimeField()
I'm trying to get the cumulative sum of the field pl in the Tip-model, this grouped by the date-field in the model Fixture. I tried the following with the Django ORM:
Tip.objects.values("prediction__fixture__date__date").annotate(
cum_pl=Window(Sum('pl'), order_by=F('prediction__fixture__date__date'))
).order_by("prediction__fixture__date__date")
But this query returns the cumulative sum per Tip instead of per date. How can I achieve this per date instead?