In [39]: from django.db.models.functions import TruncDate
...: p = Purchase.objects \
...: .annotate(date=TruncDate('event_date')) \
...: .values('date') \
...: .annotate(total=Sum('quantity')) \
...: .order_by('event_date')
...:
...:
In [40]: p
Out[40]: <PolymorphicQuerySet [{'date': datetime.date(2017, 1, 1), 'total': 10.0}, {'date': datetime.date(2018, 1, 1), 'total': 11.0}, {'date': datetime.date(2018, 7, 24), 'total': 10.0}]>
Is it possible to fill the empty months between the first and the last month with default value using the ORM? Something like {'date': DATETIME_OBJ, 'total': 0}...