On Sun, 2008-04-20 at 03:32 -0700, Julien wrote:
> Hi,
> 
> Here's my code:
> 
> class Country(models.Model):
>     ....
> 
> class Organisation(models.Model):
>     country = models.ForeignKey(Country, db_index=True)
>     ....
> 
> 
> Then, in a views, I select a number of organisations:
> 
> orgs = Organisation.objects.filter(blabla=something)
> 
> Now, I'd like to get the number of countries concerned by those
> organisations I've selected. How is that possible?

You cannot do it with a single queryset. At the SQL level this type of
query requires a "GROUP BY" construction and querysets don't do that.
Aggregate support (which includes counting related things) is something
that is being worked on, but it's still a way off.

For now, the solution is either to use custom SQL, or do one count()
queryset for each oragnisation.

Regards,
Malcolm

-- 
I just got lost in thought. It was unfamiliar territory. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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