Lets assume, that there are three models A, B, C in a Django app.
B and C are referencing to A in a ForeignKeyField.
Now I want to join two models of my Django app on a foreign key, with the extra condition, that every element out of C or B is displayed, if B.x = 1 or C.y = 2, AND (important) at least every element out of B with B.x = 1 AND every element of C with C.y=2
so that it is possible to join B and C over A with
A.objects.filter( Q(b__x=1) , Q(c__y=2)).distinct()
Unfortunately if C is not completely in B only the elements of with both conditions will be printed, but not at least every element in B.
That would require a full outer join of both tables, but I couldn't get my head around how to build a queryset for it.
I tried to concatenate both querysets like
a = A.objects.filter( Q(b__x=1) ) b = A.objects.filter( Q(c__y=2) ) c = ( a | b )
But in this case some desired values of B and C are missing. Is there a way to select all the elements I want without looping "manually" over the results and add missing elements?