I have a model:
class MyModel(models.Model):
store_id = models.TextField()
day_dt = models.DateField()
param1 = models.IntegerField()
param2 = models.IntegerField()
Some data example:
store_id | day_dt | param1 | param2
----------------------------------------
STORE1 | 2021-09-30 | 10 | 30
STORE2 | 2021-09-31 | 20 | 40
....
STORE1 | 2021-10-01 | 4 | 5
STORE1 | 2021-10-02 | 6 | 10
STORE1 | 2021-10-03 | 2 | 5
STORE2 | 2021-10-02 | 3 | 7
STORE2 | 2021-10-03 | 1 | 19
....
I need to split data into groups by store_id and interval (day_dt shoould be between 2021-10-01 and 2021-10-04):
STORE1 | 2021-10-01
STORE1 | 2021-10-02
STORE1 | 2021-10-03
and
STORE2 | 2021-10-02
STORE2 | 2021-10-03
and then apply to each (of two) groups aggregation: Avg('param1') and Avg('param2').
The expected output for data example:
store_id | param1_avg | param2_avg
----------------------------------
STORE1 | 6 | 10
STORE2 | 2 | 13
How could I do this aggregation with ORM?