Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint for react admin #273

Merged
merged 9 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def generate_result_row(
}


class CompetitionViewSet(viewsets.ReadOnlyModelViewSet):
class CompetitionViewSet(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
"""Naše aktivity"""
queryset = Competition.objects.all()
serializer_class = CompetitionSerializer
Expand Down
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
Loading