2👍
✅
Use the commit_manually decorator if you need full control over transactions. It tells Django you’ll be managing the transaction on your own.
If your view changes data and doesn’t commit() or rollback(), Django will raise a TransactionManagementError exception.
Manual transaction management looks like this:
from django.db import transaction
@transaction.commit_manually
def viewfunc(request):
...
# You can commit/rollback however and whenever you want
transaction.commit()
...
# But you've got to remember to do it yourself!
try:
...
except:
transaction.rollback()
else:
transaction.commit()
Source:stackexchange.com