﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11899	QuerySet - filter through related objects	fgrzadkowski	nobody	"Lets say we have models like:
{{{
class A(models.Model):
    pass

class B(models.Model):
    t = models.CharField(max_length=100)
    a = models.ForeignKey('A')
}}}
I've found out, that the following query is working:
{{{
A.objects.filter(b__t='1').filter(b__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 looks 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
}}}

So we have two thigns which are not documented (or I can't find it):
 * possibility to filter like above
 * if we set related_name=""bs"" in B for field a, then it affect not only foreignkey manager in A, but also filter function ({{{ .filter(bs__t='1' }}})

Or maybe its all not official features? But if not then it should be, because it's very useful :)"		closed	Documentation	1.1		invalid			Unreviewed	0	0	0	0	0	0
