Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to check if given primary key exists in django model

If using the object ---
try:
   obj = model1.objects.get(pk=20)
except DoesNotExist:
   ###do something####
    
Else ----
if model1.objects.filter(pk=20).exists():
   ###do something###
else:
  ###do otherthing###
 
PREVIOUS NEXT
Tagged: #check #primary #key #exists #django #model
ADD COMMENT
Topic
Name
5+6 =