Saturday 15 March 2014

python - Django Group By Weekday? -


I am using Django 1.5.1, Python 3.3.x, and can not use raw queries for it .

Can QuerySet be grouped by a QuerySet group, whose date uses the __ range filter? I am trying to group results in the weekdays, for a query that is between any two dates (can be equivalent to one year). I know how, but for this to find data for every past day, DB has to be fastened with 7 questions.

I have been trying different tweaks with the __ day of the week filter, but trying to figure it out for a two hour by not working Am Even Googling does not help, so I wonder if this is also possible. Here, any degenerate guru knows how to do this, if extra

code> Excluded, here is a new way of group on weekdays. Import django.db.models.functions from

  ExtractWeekDay YourObjects.objects .annotate (weekday = ExtractWeekDay ('timestamp')) .values ​​('weekday'). Anotate (count = count ('id')). Value ('workday', 'count')   

This will return as a result:

  [['day of week': 1, 'count ': 534}, {' Workday ': 2,' Count ': 574}, .......}   

It is also important to note that 1 = Sunday and Saturday = 7

No comments:

Post a Comment