Created
March 28, 2016 15:02
-
-
Save makmac213/dca600fe4d6c415dcac3 to your computer and use it in GitHub Desktop.
Django Queries
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
from django.contrib.auth.models import User | |
from django.db.models import Count | |
qs = (User.objects.all(). | |
extra(select={ | |
'm': "EXTRACT(month FROM date_joined)", | |
'd': "EXTRACT(day FROM date_joined)", | |
'y': "EXTRACT(year FROM date_joined)", | |
}). | |
values('d', 'm', 'y'). | |
annotate(count_items=Count('date_joined'))) | |
qs = qs.order_by('date_joined') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment