Skip to content

Commit

Permalink
Allow edit for schools
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Nov 12, 2023
1 parent 427aa10 commit e5a5f15
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions personal/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import status, viewsets
from rest_framework import exceptions, status, viewsets
from rest_framework.decorators import action
from rest_framework.filters import SearchFilter
from rest_framework.permissions import IsAdminUser, IsAuthenticated
Expand All @@ -26,14 +26,23 @@ class DistrictViewSet(viewsets.ReadOnlyModelViewSet):
filterset_fields = ['county', ]


class SchoolViewSet(viewsets.ReadOnlyModelViewSet):
class SchoolViewSet(viewsets.ModelViewSet):
"""Školy"""
queryset = School.objects.all()
serializer_class = SchoolSerializer
filterset_fields = ['district', 'district__county']
filter_backends = [DjangoFilterBackend, SearchFilter]
search_fields = ['name', 'street']

def destroy(self, request, *args, **kwargs):
"""Zmazanie školy"""
instance = self.get_object()
if Profile.objects.filter(school=instance).exists():
raise exceptions.ValidationError(
detail='Nie je možné zmazať školu, ktorá má priradených užívateľov.')
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)


class ProfileViewSet(viewsets.ModelViewSet):
"""Užívateľské profily"""
Expand Down

0 comments on commit e5a5f15

Please sign in to comment.