diff --git a/competition/views.py b/competition/views.py index b2fffe1d..fd88360f 100644 --- a/competition/views.py +++ b/competition/views.py @@ -12,6 +12,7 @@ from rest_framework.decorators import action from rest_framework.exceptions import ValidationError from rest_framework.permissions import IsAdminUser, IsAuthenticated +from rest_framework.request import Request from rest_framework.response import Response from base.utils import mime_type @@ -107,9 +108,15 @@ class CompetitionViewSet(mixins.RetrieveModelMixin, """Naše aktivity""" queryset = Competition.objects.all() serializer_class = CompetitionSerializer - lookup_field = 'slug' permission_classes = (CompetitionRestrictedPermission,) + @action(detail=False, url_path=r'slug/(?P\w+)') + def slug(self, request: Request, slug: str = None) -> Response: + competition: Competition = self.get_queryset().get(slug=slug) + return Response( + CompetitionSerializer(competition, many=False).data + ) + class CommentViewSet( mixins.RetrieveModelMixin,