filippo
unread,Sep 17, 2009, 7:39:45 AM9/17/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi,
Lets say I have models like:
class A(models.Model):
pass
class B(models.Model):
t = models.CharField(max_length=100)
a = models.ForeignKey('A', related_name="bs")
I've found out, that the following query is working:
A.objects.filter(bs__t='1').filter(bs__t='2')
which returns those As that have at least one B with t='1' AND at
least one B with t='2'. The underlying query lokk like this:
SELECT "search_test_a"."id" FROM "search_test_a" INNER JOIN
"search_test_b" ON ("search_test_a"."id" = "search_test_b"."a_id")
INNER JOIN "search_test_b" T3 ON ("search_test_a"."id" = T3."a_id")
WHERE ("search_test_b"."t" = E'1' AND T3."t" = E'2' ) LIMIT 21
Now my question:
Is it an official feature? I can't find it anywhere in
documentation...
regards,
Filip