I want to use two different exception, but IntegrityError part is not working. Any idea? Thanks in advance.
new_sample = Samples()
try:
if(Samples.objects.get(p_id_s=listItem[0])):
Samples.objects.filter(p_id_s=listItem[0]).update(**new_item_details)
except Samples.DoesNotExist:
new_sample.__dict__.update(new_item_details)
new_sample.save()
except IntegrityError:
messages.error(request, "Already have that id!")
return HttpResponseRedirect("/")