[Answered ]-Django – 3-model set all, with joining?

2👍

You can execute this query to get all the C’s associated via B’s to your A:

C.objects.filter(the_b__the_a=instance_of_a)

where instance_of_a is some instance of class A.

For more information, see http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

0👍

This doesn’t directly answer your question, but it’s possible in straight SQL with a single query, so it may be possible in Django, but it depends on the way their wrappers over SQL were written.

Example:

SELECT C.* FROM B,C WHERE C.the_b = B.id AND B.the_a = ?

Where ? is the ID of the A you are interested in.

👤davr

0👍

OK, I should have RTM:

my_a = Some instance of A

cs_for_my_a = C.objects.filter(the_b__the_a=my_a)

👤Colin

Leave a comment