[Django]-Is there way to construct a Q object, that represents a EmptyQueryset, i.e. that always returns an empty result?

3👍

qList = []
try:
  objectA = ...
  qList.append(Q(foo=objectA.bar))
except ...:
  ...
 ...

result = MyOtherMdel.objects.filter(reduce(operator.or_, qList),
  **other_filter_conditions)

0👍

For Querysets there is the none() method, which always returns the EmptyQueryset. Is there something similar for Q objects?

Q(pk=-1)

👤H1D

Leave a comment