I have the following:

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}...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6cc40f0f-17d1-4e15-a01c-8610647c990e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to