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=True)
    title = models.TextField( blank=True)
    def __unicode__(self):
        return "%s / %s"%(self.title, self.location)


Now I want to get a list of titles and the number of occurrences.  The
following SQL gives me what I want in SQLITE:


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 following:

r = Reference.objects.values('title').extra(select={'title_count' :
'COUNT(*)'}).distinct()

but this gives me only title, not the title_count, which does not show
up in the results.

I guess I am doing something wrong, but can't quite figure out what.

Any help appreciated,

Chris

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to