title: Django race condition inside a transaction
body: <p>I have Django 1.11 app with PostgreSQL.
  Take a look at code below.</p>
  
  <p>Is it possible to have race condition there? I am afraid I could get race condition on <code>diff=-account.hours</code>. Does <code>transaction.atomic</code> save from race condition?</p>
  
  <pre><code>from django.db import transaction
  
  def write_off(account_ids):
      accounts = Account.objects.filter(id__in=account_ids)
      for account in accounts:
  
          with transaction.atomic():
              MyLog.objects.create(
                  hours=0,
                  operation_type=LOG_OPERATION_WRITE_OFF,
                  diff=-account.hours,
              )
              Account.objects.filter(pk=account.pk).update(hours=0)
  </code></pre>