25π
β
Alex pointed to the right answer in the comment:
Count number of records by date in Django
Credit goes to ara818
Guidoism.objects.extra({'created':"date(created)"}).values('created').annotate(created_count=Count('id'))
from django.db.models import Count
Guidoism.objects \
# get specific dates (not hours for example) and store in "created"
.extra({'created':"date(created)"})
# get a values list of only "created" defined earlier
.values('created')
# annotate each day by Count of Guidoism objects
.annotate(created_count=Count('id'))
I learn new tricks every day reading stack.. awesome!
0π
Use the count method:
YourModel.objects.filter(published_on=datetime.date(2011, 4, 1)).count()
π€crodjer
- Django admin: how to disable edit and delete link for foreignkey
- Could not import settings 'myproject.settings' (Is it on sys.path?): No module named pinax
- Django/Nginx β Error 403 Forbidden when serving media files over some size
- Is there a way to hook Django's unittest into PyUnit in eclipse?
Source:stackexchange.com