Deep Shah Deep Shah - 1 year ago 79
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:

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download