In Django 1.5/1.6 version -
signup_count = list(User.objects.filter(
profile__user_type='learner').order_by(
'-id').extra({
'date_only': "date(date_joined)"}).values(
'date_only').annotate(
signup_count=Count('id'))[:40])
It used to return list with
[{ 'date_only':, 'signup_count': }]
Now, as the extra is deprecated in newer version of Django, here the work around to get the same -
from django.db.models.expressions import Func
# Create custom sql function
class ExtractDateFunction(Func):
function = "DATE"
signup_signup = list(User.objects.filter(
profile__user_type='learner').order_by('-id')annotate(
date_only=ExtractDateFunction("date_joined")).values(
'date_only').annotate(
teacher_count=Count('id'))[:40])
This should give you the same results as before.
signup_count = list(User.objects.filter(
profile__user_type='learner').order_by(
'-id').extra({
'date_only': "date(date_joined)"}).values(
'date_only').annotate(
signup_count=Count('id'))[:40])
It used to return list with
[{ 'date_only':
Now, as the extra is deprecated in newer version of Django, here the work around to get the same -
from django.db.models.expressions import Func
# Create custom sql function
class ExtractDateFunction(Func):
function = "DATE"
signup_signup = list(User.objects.filter(
profile__user_type='learner').order_by('-id')annotate(
date_only=ExtractDateFunction("date_joined")).values(
'date_only').annotate(
teacher_count=Count('id'))[:40])
This should give you the same results as before.