[collector views] wrap attempt to create a new Teil in a transaction
This commit is contained in:
parent
f1ab7afb6f
commit
59596f3064
1 changed files with 3 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
|
||||
from django.db import transaction
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.urls import reverse
|
||||
|
@ -30,7 +31,8 @@ def detail(request: HttpRequest, teil_id) -> HttpResponse:
|
|||
|
||||
def enter(request: HttpRequest) -> HttpResponse:
|
||||
try:
|
||||
Teil.objects.create(name=request.POST["new_name"])
|
||||
with transaction.atomic():
|
||||
Teil.objects.create(name=request.POST["new_name"])
|
||||
except Exception:
|
||||
logger.warning("Teil already existed")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue