|
2 | 2 |
|
3 | 3 | from django import forms |
4 | 4 | from django.db import transaction |
5 | | -from django.http import Http404, HttpResponseBadRequest |
| 5 | +from django.http import HttpResponseBadRequest |
6 | 6 | from django.shortcuts import render, get_object_or_404, redirect |
7 | 7 | from django.urls import reverse |
8 | 8 | from django.views.generic import FormView, ListView |
9 | 9 | from rest_framework import viewsets, mixins |
10 | 10 | from rest_framework.decorators import detail_route |
11 | | -from rest_framework.exceptions import ValidationError, APIException |
| 11 | +from rest_framework.exceptions import ValidationError, APIException, PermissionDenied |
12 | 12 | from rest_framework.viewsets import GenericViewSet |
13 | 13 |
|
14 | 14 | from frisbeer.models import * |
@@ -78,6 +78,11 @@ def create_teams(self, request, pk=None): |
78 | 78 | print("Created") |
79 | 79 | return redirect(reverse("frisbeer:games-detail", args=[pk])) |
80 | 80 |
|
| 81 | + def destroy(self, request, *args, **kwargs): |
| 82 | + if request.user and not request.user.is_superuser and self.get_object().players.count() > 0: |
| 83 | + raise PermissionDenied("Only admins can delete games with players in them") |
| 84 | + return super().destroy(request, *args, **kwargs) |
| 85 | + |
81 | 86 |
|
82 | 87 | class LocationViewSet(viewsets.ModelViewSet): |
83 | 88 | queryset = Location.objects.all() |
|
0 commit comments