Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rivrxsq committed Jan 11, 2025
1 parent 65378d4 commit d72b241
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 47 deletions.
18 changes: 4 additions & 14 deletions cinema/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from django.urls import path
from rest_framework.routers import DefaultRouter
from cinema.views import (
MovieViewSet,
GenreList,
GenreDetail,
CinemaHallList,
CinemaHallDetail,
ActorList,
ActorDetail
MovieViewSet, GenreList, GenreDetail,
CinemaHallViewSet, ActorList, ActorDetail
)

router = DefaultRouter()
router.register("movies", MovieViewSet, basename="movie")
router.register("cinema_halls", CinemaHallViewSet, basename="cinema_hall")

app_name = "cinema"

Expand All @@ -20,10 +16,4 @@
path("genres/<int:pk>/", GenreDetail.as_view(), name="genre-detail"),
path("actors/", ActorList.as_view(), name="actor-list"),
path("actors/<int:pk>/", ActorDetail.as_view(), name="actor-detail"),
path("cinema_halls/", CinemaHallList.as_view(), name="actor-list"),
path(
"cinema_halls/<int:pk>/",
CinemaHallDetail.as_view(),
name="actor-detail"
),
] + router.urls
] + router.urls
49 changes: 16 additions & 33 deletions cinema/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from rest_framework import status, mixins, generics, viewsets
from rest_framework import status, viewsets
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView
from rest_framework.mixins import (
ListModelMixin,
CreateModelMixin,
RetrieveModelMixin,
UpdateModelMixin,
DestroyModelMixin
)
from rest_framework.response import Response
from rest_framework.views import APIView

from django.shortcuts import get_object_or_404
from rest_framework.viewsets import GenericViewSet

from cinema.models import Movie, Genre, Actor, CinemaHall
from cinema.serializers import (
Expand Down Expand Up @@ -55,46 +64,20 @@ def delete(self, request, pk):
return Response(status=status.HTTP_204_NO_CONTENT)


class ActorList(
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView
):
class ActorList(ListCreateAPIView):
queryset = Actor.objects.all()
serializer_class = ActorSerializer

def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)


class ActorDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView
):
class ActorDetail(RetrieveUpdateDestroyAPIView):
queryset = Actor.objects.all()
serializer_class = ActorSerializer

def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)

def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)

def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)


class CinemaHallList(generics.ListCreateAPIView):
queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer


class CinemaHallDetail(generics.RetrieveUpdateDestroyAPIView):
class CinemaHallViewSet(
GenericViewSet, ListModelMixin, CreateModelMixin,
RetrieveModelMixin, UpdateModelMixin, DestroyModelMixin
):
queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer

Expand Down

0 comments on commit d72b241

Please sign in to comment.