Skip to content

Commit

Permalink
add views, urls for CinemaHall
Browse files Browse the repository at this point in the history
  • Loading branch information
b4oody committed Dec 28, 2024
1 parent 38a927f commit d7fcfac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions cinema/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/", GenreDetail.as_view(), name="genres-detail"),
Expand All @@ -16,6 +30,12 @@
path("actors/<int:pk>/", ActorDetail.as_view(), name="actors-detail"),


path("cinema_halls/", cinema_hall_list, name="cinema-hall-list"),
path("cinema_halls/<int:pk>/", cinema_hall_detail, name="cinema-hall-detail"),




]

app_name = "cinema"
17 changes: 15 additions & 2 deletions cinema/views.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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

0 comments on commit d7fcfac

Please sign in to comment.