Django many-to-many second-level filtering

Consider three django models: AA, BB, and CC. AA has an M2M link to BB and BB has an M2M link to CC.

I have one copy of AA. How to execute QuerySet filter () on a set of CC instances that are M2M associated with BB instances that are M2M associated with this single AA instance?

+3
source share
1 answer

The following worked for me:

CC.objects.filter( bb__aa = aa_instance )

This creates a QuerySet that you can manipulate ...

Found the answer in django documentation here .

+4
source

Source: https://habr.com/ru/post/1748429/


All Articles