Skip to content

Commit

Permalink
Change lookup field to id and add get_one by slug
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Dec 8, 2023
1 parent 26f8c61 commit 890be10
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<slug>\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,
Expand Down

0 comments on commit 890be10

Please sign in to comment.