Ok, I see. After some mucking around, I managed to make it work like
this:

orgs = Organisation.objects.filter(blabla=something)
values = orgs.values('country')
country_id_list = [value['country'] for value in values]
num_countries = Country.objects.filter(id__in=country_id_list).count()


Looks a bit hackish but it works and is fairly fast.

Regards,

Julien

On Apr 20, 9:11 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> 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 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