title: Control Atomic Transactions in Django
body: <p>I have a simple library application. In order to force 3 actions to commit as one action, and rollback if any of the actions fail, I made the following code changes:</p>
  
  <p>In <code>settings.py</code>:</p>
  
  <pre><code>AUTOCOMMIT=False
  </code></pre>
  
  <p>In <code>forms.py</code></p>
  
  <pre><code>from django.db import IntegrityError, transaction
      class CreateLoan(forms.Form):
          #Fields...
          def save(self):
              id_book = form.cleaned_data.get('id_book', None)
              id_customer = form.cleaned_data.get('id_customer', None)
              start_date = form.cleaned_data.get('start_date', None)
              book = Book.objects.get(id=id_book)
              customer = Customer.objects.get(id=id_customer)
              new_return = Return(
                  book=book
                  start_date=start_date)
              txn=Loan_Txn(
                  customer=customer,
                  book=book,
                  start_date=start_date
              )
  
              try
                  with transaction.atomic():
                      book.update(status="ON_LOAN")
                      new_return.save(force_insert=True)
                      txn.save(force_insert=True)
              except IntegrityError:
                  raise forms.ValidationError("Something occured. Please try again")
  </code></pre>
  
  <p>Am I still missing anything with regards to this? I'm using Django 1.9 with Python 3.4.3 and the database is MySQL.</p>