diff --git a/cinema/serializers.py b/cinema/serializers.py index 97cae25c1..b05427980 100644 --- a/cinema/serializers.py +++ b/cinema/serializers.py @@ -28,8 +28,8 @@ def update(self, instance, validated_data): class CinemaHallSerializer(serializers.Serializer): id = serializers.IntegerField(read_only=True) name = serializers.CharField(max_length=255) - rows = serializers.IntegerField(read_only=True) - seats_in_row = serializers.IntegerField(read_only=True) + rows = serializers.IntegerField(read_only=False) + seats_in_row = serializers.IntegerField(read_only=False) def create(self, validated_data): return CinemaHall.objects.create(**validated_data) diff --git a/cinema/urls.py b/cinema/urls.py index 1d74b5776..5c2d6c676 100644 --- a/cinema/urls.py +++ b/cinema/urls.py @@ -12,7 +12,7 @@ router = routers.DefaultRouter() router.register("movies", MovieViewSet) -router.register("cinema-halls", CinemaHallViewSet) +router.register("cinema_halls", CinemaHallViewSet) urlpatterns = [ path("", include(router.urls)), diff --git a/cinema/views.py b/cinema/views.py index 8d5b9971c..4795422a1 100644 --- a/cinema/views.py +++ b/cinema/views.py @@ -43,6 +43,14 @@ def put(self, request, pk): return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + def patch(self, request, pk): + genre = self.get_object(pk) + serializer = GenreSerializer(genre, data=request.data, partial=True) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + def delete(self, request, pk): genre = self.get_object(pk) genre.delete() @@ -50,7 +58,9 @@ def delete(self, request, pk): class ActorList( - mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView + mixins.ListModelMixin, + mixins.CreateModelMixin, + generics.GenericAPIView, ): queryset = Actor.objects.all() serializer_class = ActorSerializer @@ -68,7 +78,6 @@ class ActorDetail( mixins.DestroyModelMixin, generics.GenericAPIView, ): - queryset = Actor.objects.all() serializer_class = ActorSerializer @@ -78,6 +87,9 @@ def get(self, request, *args, **kwargs): def put(self, request, *args, **kwargs): return self.update(request, *args, **kwargs) + def patch(self, request, *args, **kwargs): + return self.partial_update(request, *args, **kwargs) + def delete(self, request, *args, **kwargs): return self.destroy(request, *args, **kwargs) @@ -90,7 +102,6 @@ class CinemaHallViewSet( mixins.DestroyModelMixin, viewsets.GenericViewSet, ): - queryset = CinemaHall.objects.all() serializer_class = CinemaHallSerializer