how to check if an entry exists in a model django

Solutions on MaxInterview for how to check if an entry exists in a model django by the best coders in the world

showing results for - "how to check if an entry exists in a model django"
Bray
23 Jul 2016
1try:
2   obj = model1.objects.get(pk=20)
3except DoesNotExist:
4   #do something
5    
6Else ----
7if model1.objects.filter(pk=20).exists():
8   #do something
9else:
10  #do otherthing