Deep Shah Deep Shah - 7 months ago 46
Python Question

What is the exact usage of exists()?

I am using it as

if ModelName.objects.get(fieldname=value).exists():

I either get the error 'ModelName' object has no attribute 'exists' or it throws a

Related doc:


You should apply it to queryset, not a single object, try:

if ModelName.objects.filter(fieldname=value).exists():

If queryset is not empty, this will return True.