Deep Shah Deep Shah - 6 months ago 41
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.