Filtering second level of Many-to-Many relations in Django
Consider three django models: AA, BB and CC. AA has an M2M reference to BB and BB has an M2M reference to CC.
I have a single instance of AA. How do I execute a filter() QuerySet over the set of CC ins开发者_开发百科tances that are M2M related the the BB instances that are M2M related to that single AA instance?
The following worked for me:
CC.objects.filter( bb__aa = aa_instance )
That produces a QuerySet you can further manipulate...
Found the answer in the django documentation here.
精彩评论