Skip to content
Advertisement

Why Django think OR is complex?

I read some model operation from Django’s document, and find this

enter image description here

I’m curious that OR in WHERE is just basic concept, why Django think it’s a complex query?

Advertisement

Answer

Actually, what’s “more complex” here is the full query syntax, whatever the logical operator. The full syntax for an “AND” query is

MyModel.objects.filter(Q(foo="bar") & Q(quux="baaz"))

but since in practice you more often use AND queries than OR queries, the ORM provides a shortcut for AND queries:

MyModel.objects.filter(foo="bar", quux="baaz")
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement