2👍
✅
In the case that objects do exist, doing two queries is less efficient than doing one.
In the case that no objects exist, I can’t think why exists()
would be noticeably faster than count()
.
So I would stick with:
c = Model.objects.filter(...).count()
One disadvantage of doing exists()
first is that you have not set c
when exists()
returns False
. This could lead to NameError
if you’re not careful.
Source:stackexchange.com