Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
markus2812 committed Dec 12, 2023
1 parent bf2d31f commit 11aafd3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.db.models import F, Count
from rest_framework import viewsets, mixins
from rest_framework.authentication import TokenAuthentication
from rest_framework.mixins import ListModelMixin, CreateModelMixin
from rest_framework.pagination import PageNumberPagination
from rest_framework.permissions import IsAuthenticated

Expand Down Expand Up @@ -54,12 +55,14 @@ class CinemaHallViewSet(
http_method_names = ["get", "post"]


class MovieViewSet(viewsets.ModelViewSet):
class MovieViewSet(mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
viewsets.GenericViewSet):
queryset = Movie.objects.prefetch_related("genres", "actors")
serializer_class = MovieSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)
http_method_names = ["get", "post", "retrieve"]

@staticmethod
def _params_to_ints(qs):
Expand Down Expand Up @@ -97,7 +100,12 @@ def get_serializer_class(self):
return MovieSerializer


class MovieSessionViewSet(viewsets.ModelViewSet):
class MovieSessionViewSet(mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet):
queryset = (
MovieSession.objects.all()
.select_related("movie", "cinema_hall")
Expand All @@ -113,7 +121,6 @@ class MovieSessionViewSet(viewsets.ModelViewSet):
serializer_class = MovieSessionSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)
http_method_names = ["get", "post", "put", "patch", "delete"]

def get_queryset(self):
date = self.request.query_params.get("date")
Expand Down Expand Up @@ -155,7 +162,6 @@ class OrderViewSet(
pagination_class = OrderPagination
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
http_method_names = ["get", "post"]

def get_queryset(self):
return Order.objects.filter(user=self.request.user)
Expand Down

0 comments on commit 11aafd3

Please sign in to comment.