From d7fcfac6572f974be9e8d9eb0d615f665be3b5f7 Mon Sep 17 00:00:00 2001 From: VR Date: Sat, 28 Dec 2024 02:24:40 +0200 Subject: [PATCH] add views, urls for CinemaHall --- cinema/urls.py | 20 ++++++++++++++++++++ cinema/views.py | 17 +++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cinema/urls.py b/cinema/urls.py index bb8233a4..a9e2ec93 100644 --- a/cinema/urls.py +++ b/cinema/urls.py @@ -5,8 +5,22 @@ GenreDetail, ActorList, ActorDetail, + CinemaHallViewSet, ) + +cinema_hall_list = CinemaHallViewSet.as_view( + actions={"get": "list", + "post": "create" + }) + +cinema_hall_detail = CinemaHallViewSet.as_view( + actions={"get": "retrieve", + "put": "update", + "patch": "partial_update", + "delete": "destroy", + }) + urlpatterns = [ path("genres/", GenreList.as_view(), name="genres-list"), path("genres//", GenreDetail.as_view(), name="genres-detail"), @@ -16,6 +30,12 @@ path("actors//", ActorDetail.as_view(), name="actors-detail"), + path("cinema_halls/", cinema_hall_list, name="cinema-hall-list"), + path("cinema_halls//", cinema_hall_detail, name="cinema-hall-detail"), + + + + ] app_name = "cinema" diff --git a/cinema/views.py b/cinema/views.py index b0f379c3..5ff51da5 100644 --- a/cinema/views.py +++ b/cinema/views.py @@ -1,11 +1,11 @@ from django.shortcuts import get_object_or_404 -from rest_framework import status, generics, mixins +from rest_framework import status, generics, mixins, viewsets from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework.views import APIView from cinema.models import Genre, Actor, CinemaHall, Movie -from cinema.serializers import MovieSerializer, GenreSerializer, ActorSerializer +from cinema.serializers import MovieSerializer, GenreSerializer, ActorSerializer, CinemaHallSerializer class GenreList(APIView): @@ -88,3 +88,16 @@ def patch(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs): return self.destroy(request, *args, **kwargs) + + +class CinemaHallViewSet( + mixins.ListModelMixin, + mixins.CreateModelMixin, + mixins.RetrieveModelMixin, + mixins.UpdateModelMixin, + mixins.DestroyModelMixin, + viewsets.GenericViewSet +): + queryset = CinemaHall.objects.all() + serializer_class = CinemaHallSerializer +