Always False Q object

Viewed 2899

In Django ORM, how does one go about creating a Q object that is always False?

This is similar to the question about always True Q objects, but the other way round.

Note that this doesn't work:

Foobar.objects.filter(~Q()) # returns a queryset which gives all objects

Why do I want a Q object instead of the simple False value? So that I can combine it with other Q values, like this for example:

condition = always_true_q_object
if something_or_other:
    condition = condition | foobar_that_returns_a_q_object()
if something_or_other2:
    condition = condition | foobar_that_returns_a_q_object2()
3 Answers
Related