settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'diva',
'USER': 'root',
'PASSWORD': 'admin',
'ATOMIC_REQUESTS':True,
'HOST': 'localhost',
'PORT': '3306',
},
}
views.py
def create_project(self, request):
try:
with transaction.atomic():
code here
except Exception as e:
print "Exception--->",str(e)
response = {"status":"failed",'response': ugettext("projects.services.create_project.failure")}
stat = status.HTTP_400_BAD_REQUEST
return Response(response, status=stat)
in my code, if it raises ObjectDoesNotExist Exception rollback is not happening, can anyone explain how transactions work in django with example.