Reputation: 1402
Is there any way to specify a Django Queryset, which will do nothing but still be valid Queryset? Empty queryset should ideally not call DB and results would be empty.
Upvotes: 2
Views: 268
Reputation: 30453
Use MyModel.objects.none()
which will return an EmptyQuerySet
, which is a QuerySet
subclass that always evaluates to an empty list.
For eg., if you have a model class Entry
(or just use models.Model
), you can simply create an EmptyQuerySet
by:
>>> Entry.objects.none()
[]
Upvotes: 1