Re: SQL in queryset extra method not showing in results

2008-11-11 Thread Malcolm Tredinnick
On Mon, 2008-11-10 at 14:52 -0800, chris wrote: > Now, to answer myself, I found the solution: > > qs = > Reference.objects.all().extra(select={'title_count' > :'COUNT(*)'}).values('title', > 'title_count') > qs.query.group_by = ['title'] > > This gives me exactly the aggregated list of titles

Re: SQL in queryset extra method not showing in results

2008-11-10 Thread chris
Now, to answer myself, I found the solution: qs = Reference.objects.all().extra(select={'title_count' :'COUNT(*)'}).values('title', 'title_count') qs.query.group_by = ['title'] This gives me exactly the aggregated list of titles with the number of occurrences. The trick with group_by is undocu

Re: SQL in queryset extra method not showing in results

2008-11-10 Thread chris
Thanks Malcolm, This brings me one step closer, but not quite there. On Nov 10, 8:21 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > SELECT title, COUNT (*) AS count FROM persons_reference GROUP BY title > > ORDER BY count DESC > > > Trying to get the same from the Django ORM, I do the fol

Re: SQL in queryset extra method not showing in results

2008-11-10 Thread Malcolm Tredinnick
On Sun, 2008-11-09 at 22:19 -0800, chris wrote: > Dear Django users, > > Here is the problem I am trying to solve: > > I have a Reference object defined as follows: > > class Reference(models.Model): > person = models.ForeignKey(Person) > author = models.CharField(max_length = 20, bla

SQL in queryset extra method not showing in results

2008-11-09 Thread chris
Dear Django users, Here is the problem I am trying to solve: I have a Reference object defined as follows: class Reference(models.Model): person = models.ForeignKey(Person) author = models.CharField(max_length = 20, blank=True) location = models.CharField(max_length=255, blank=Tru