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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -