In Django, I'm trying to filter Foo objects by whether a Bar object exists with the same values. The code I have below works fine for non-null values. But I also want it to return true if Foo.baz and Bar.baz are both null.
Foo.objects.filter(Exists(Bar.objects.filter(baz=OuterRef('baz'), qux=OuterRef('qux'))
I know NULL is not equal to NULL in SQL so have tried various formulations like this:
baz__isnull=...
But I'm not getting very far. Is there a way to achieve this?