Refactor group and music game models to use UniqueConstraint; update form error handling in templates
This commit is contained in:
parent
43ec6aafc4
commit
245a2503e2
5 changed files with 84 additions and 14 deletions
|
@ -7,6 +7,7 @@ from django.conf import settings
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.db import IntegrityError
|
||||
from django.db.models import Count, Q
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
|
@ -40,7 +41,11 @@ class GroupMixin:
|
|||
class GroupCreateView(LoginRequiredMixin, GroupMixin, CreateView):
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
return super().form_valid(form)
|
||||
try:
|
||||
return super().form_valid(form)
|
||||
except IntegrityError:
|
||||
form.add_error("name", "Ce nom de groupe existe déjà.")
|
||||
return super().form_invalid(form)
|
||||
|
||||
|
||||
class GroupUpdateView(OwnerFilterMixin, GroupMixin, UpdateView):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue