Make function atomic

This commit is contained in:
Oliver Walters 2019-09-17 14:17:49 +10:00
parent 08f958dd72
commit 774872e6a6

View File

@ -6,6 +6,7 @@ Django views for interacting with Part app
from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.db import transaction
from django.shortcuts import get_object_or_404
from django.shortcuts import HttpResponseRedirect
from django.utils.translation import gettext_lazy as _
@ -194,11 +195,15 @@ class PartSetCategory(AjaxUpdateView):
}
if valid:
for part in self.parts:
part.set_category(self.category)
self.set_category()
return self.renderJsonResponse(request, data=data, form=self.get_form(), context=self.get_context_data())
@transaction.atomic
def set_category(self):
for part in self.parts:
part.set_category(self.category)
def get_context_data(self):
""" Return context data for rendering in the form """
ctx = {}