python - How to filter Django objects to accept matches and NULLs? -
i have model has foreignkey
field, null=true
.
the field-semantics null entry permissive, while non-null entry binds single row in foreign table.
i want build orm filter corresponds to:
select * foo foo.fk_field = ? or foo.fk_field null
(where question mark represents single value in foreign table.)
is possible in django orm, need resort raw
query?
use q objects:
from django.db.models import q foo.objects.filter(q(fk_field=fk_value) | q(fk_field=none))
Comments
Post a Comment