Skip to content
Advertisement

How to compose Django Model Filter for relation existence?

There is a many-to-many relationship between A and B. There are 3 tables to represent that relationship. TableA, TableB, TableAB

Now I have another table TableC where it has a foreign key to TableA, and I want to filter objects from TableC where it has a relationship with TableB.

The following is high-level code to give you the idea how the models look like.

The SQL query looks like

Advertisement

Answer

I found a solution

It runs the following query

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement