title: How to do to a manual commit using Django
body: <p>I would like to execute a transaction to delete some values, after that, count in db and if the result is &lt; 1, rollback, i tried the following code:</p>
  
  <pre><code>@login_required
  @csrf_exempt
  @transaction.atomic
  def update_user_groups(request):
      if request.POST:
          userId = request.POST['userId']
          groups = request.POST.getlist('groups[]')
          result = None
          with transaction.atomic():
              try:
                  GroupsUsers.objects.filter(user_id=int(userId)).delete()
                  for group in groups:
                      group_user = GroupsUsers()
                      group_user.user_id = userId
                      group_user.group_id = group
                      group_user.save()
                  count = UsersInAdmin.objects.all().count()
                  if count &lt; 1:
                      transaction.commit()
                  else:
                      transaction.rollback()
              except Exception, e:
                  result = e
      return JsonResponse(result, safe=False)
  </code></pre>
  
  <p>Thanks,</p>