Hello,

I want to create a QuerySet object which select objects from a table
which a referenced by another table, but I can't find how to do that.

Here is an example :

    class Article(models.Model):
        [...]

    class Photo(models.Model):
        article = models.ForeignKey(Article)
        [...]

What I want is "every articles which have at least one photo" (and the
possibility to add more filter after that, eventually).


Currently, I'm using something like :

    Article.objects.filter(photos__in=Photo.objects.all())

but this is horribly inefficient, since there is more than 40000
photos in the database (and PostgreSQL doesn't accept this query
either, but this is another problem ...)

How can I do that ?


Thanks for your answer,

 - Jonathan


--~--~---------~--~----~------------~-------~--~----~
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