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
- [Answered ]-How to enforce user to enter a datefield in DD-MM-YYYY format, and timefield in 'HH:MM' format in django?
- [Answered ]-Django view method signature is it possible to match GET parameters?
- [Answered ]-Dynamically generate one value in a Django include tag
- [Answered ]-Unhandled exception in thread started
- [Answered ]-Django – Invalid literal for int() with base 10 python django
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)
- [Answered ]-How to automate django dumpdata?
- [Answered ]-Accessing objects from another model using foreign key
- [Answered ]-How to use a web API with Django
- [Answered ]-Avoiding multiple queries to display model data on Django admin
Source:stackexchange.com