Let's say I have two tables in Django, TableA
and TableB
. Table A contains some boolean field, bool
, and TableB
contains a foreign key field, for_field
to TableA
, which can be Null.
class TableA(models.Model):
bool = models.BooleanField()
class TableB(models.Model):
for_field = models.ForeignKey('TableA', null=True)
If I want to filter TableB so as to get all the entries where for_field.bool
is True
or for_field
is Null
, what is the shortest way to achieve this?
I'm using .filter((Q(for_field__is_null=True) | Q(for_field__bool=True))
, but I wonder if there's shorter code for this.