开发者

Filtering second level of Many-to-Many relations in Django

开发者 https://www.devze.com 2023-01-01 23:36 出处:网络
Consider three django models: AA, BB and CC. AA has an M2M reference to BB and BB has an M2M reference to CC.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消