[Question] Django 2 - how to sum values based on filter and group by Year-Month

2018-07-26 Thread Charles Sartori
I have the following table: 2018-01-01 10 2018-01-15 20 2018-01-31 30 2018-02-01 10 2018-03-01 10 2018-03-20 20 I need to Sum() the values filtering it with 1 - sum(values) where date < first day of the month 2 - sum(values) where date < last day of the month Expec

How to fill empty months using Django queryset

2018-07-24 Thread Charles Sartori
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') ...: .

return objects with datetime field with default_timezone

2016-03-29 Thread Charles Sartori
I am using USE_TZ = True and TIME_ZONE = 'America/Sao_Paulo' when I save some datetime field it will save on MySQL in UTC as expected, but when I query this object and print object.date it still in UTC, I tried to set timezone.activate(timezone.get_default_timezone()) before querying but the r