I am trying to handle both add new and edit object. My views.py file is like-
personal_data=Personal.objects.create(emp_fname=first_name, emp_mname=middle_name, emp_lname=last_name)
# rest of object is created here
try:
print "pk", pk
with transaction.atomic():
if pk != None:
print "hey"
#save model goes here
messages.add_message(request, messages.INFO, 'Data updated successfully')
else:
print "hello"
personal_data.save()
family_data.save()
address_data.save()
education_data.save()
pre_company_data.save()
messages.add_message(request, messages.INFO, 'Data saved successfully')
except IntegrityError:
handle_exception()
if-else condition works properly but data is saved in both cases. even if I commented the code shown above still data goes to database.