N
N
Northxstar2020-01-17 20:46:30
Django
Northxstar, 2020-01-17 20:46:30

How to annotate on multiple field values ​​in Django ORM?

We have the simplest model of the form:

Date = models.DateField()
Parameter = models.TextField()
Amount = models.BigIntegerField()

It is necessary to get a selection of the form [DATE | SUM Amount for Param1 | SUM Amount forParam2 .... etc.]
For the option without a parameter (amount per day, roughly speaking), I did this:
response = models.MyModel.objects.filter(Date__gte=foodate).filter(Date__lte=bardate).values('Date').annotate(sum=Sum('Amount')).order_by()

How to make such a selection, taking into account the fact that there can be a wide variety of parameter values?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question