Django group by dates and SUM values include SUM zero
values = self.model.objects.values('datetime').annotate(data_sum=Sum('data')).filter(datetime__range=( ? ) )
I want to add all the values of each day in the month. Include days on which the sum is zero.
Why sum operate on both datetime and data?
I tried to everywhere on django doc, here on stack but didn't find something coherent with my problem. Any suggestion ?
There is a post similar to this, but it does not display the sum of the day values that is zero Django group by dates and SUM values
+---------------------+-----------+
| datetime | SUM(data) |
+---------------------+-----------+
| 2013-07-01 | 489 |
| 2013-07-02 | 2923 |
| 2013-07-03 | 984 |
| 2013-07-04 | 2795 |
| 2013-07-05 | 0 |
| 2013-07-06 | 1365 |
| 2013-07-07 | 1331 |
| 2013-07-08 | 0 |
| 2013-07-09 | 919 |
| 2013-07-10 | 722 |
| 2013-07-11 | 731 |
| 2013-07-12 | 489 |
| 2013-07-13 | 2923 |
| 2013-07-14 | 984 |
| 2013-07-15 | 2795 |
| 2013-07-16 | 0 |
| 2013-07-17 | 0 |
| 2013-07-18 | 0 |
| 2013-07-19 | 0 |
| 2013-07-20 | 919 |
| 2013-07-21 | 722 |
| 2013-07-22 | 731 |
| 2013-07-23 | 1365 |
| 2013-07-24 | 1331 |
| 2013-07-25 | 0 |
| 2013-07-26 | 919 |
| 2013-07-27 | 722 |
| 2013-07-28 | 731 |
| 2013-07-29 | 1365 |
| 2013-07-30 | 1331 |
| 2013-07-31 | 0 |
+---------------------+-----------+
11 rows in set (1.45 sec)