开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜