Created
January 27, 2016 20:55
-
-
Save repodevs/b9fd93987832b3b43296 to your computer and use it in GitHub Desktop.
models grouping by date and count data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple snippet data to grouping and counting a django models | |
# for example in this data | |
# I have fields with attribute DateTimeField | |
# so I use `Model.objects.datetimes` | |
# Because I just want get day,month,year | |
# If you just use fields `DateTime` Prefer you can use `Model.objects.date` | |
users = Model.objects.all() # Models to be grouping | |
count_user = [{'val': users.filter(date_joined__day=x.day,date_joined__month=x.month,date_joined__year=x.year).count(), 'date':x.strftime('%Y-%m-%d')} for x in Model.objects.datetimes('date_joined','day')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment