You can find additional information in docs : near exists()
, but exists()
only works for QuerySet
Returns True if the QuerySet contains any results, and False if not. This tries to execute the query in the simplest and fastest way, but it performs almost the same query as a regular QuerySet query.
exists () is useful for searches related to the membership of objects in QuerySet, as well as to the existence of any objects in QuerySet, especially in the context of a large QuerySet.
But ObjectDoesNotExist
only works with get()
.
You can also try a different approach:
user = User.objects.filter(id=2) if user:
source share