Not the exact answer you were looking for, but I was only wondering, if you have already figured the actual SQL query then why not simply use that instead.
It's not mandatory to use the model query APIs, if your query is complex. Using the raw() API would still yield you model querysets or instances. https://docs.djangoproject.com/en/dev/topics/db/sql/ On Fri, Aug 5, 2011 at 11:21 PM, Simon Zimmermann <simon...@gmail.com>wrote: > In SQL we can do > > SELECT MONTH(date_joined), YEAR(date_joined), COUNT(id) as > joined_month > FROM auth_user > GROUP BY MONTH(date_joined), YEAR(date_joined) > ORDER BY YEAR(date_joined), MONTH(date_joined) > > Which yields a table like this > > MONTH(date_joined) YEAR(date_joined) joined_month > 3 2001 24 > 4 2001 86 > 5 2001 133 > 6 2001 61 > > Is it possible to do this with the Django ORM? So far I only got half > of it with the following > > User.objects.all().extra({'month_joined': > > 'month(date_joined)'}).values('month_joined').annotate(created_count=Count('id')) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.