diff --git a/cinema/serializers.py b/cinema/serializers.py index 8a30617b1..2129a6de8 100644 --- a/cinema/serializers.py +++ b/cinema/serializers.py @@ -18,8 +18,6 @@ def update(self, instance, validated_data): "description", instance.description ) instance.duration = validated_data.get("duration", instance.duration) - # instance.actors.set(validated_data.get("actors", instance.actors)) - # instance.genres.set(validated_data.get("genres", instance.genres)) instance.save() diff --git a/cinema/views.py b/cinema/views.py index 8696a679e..e1f2cb2fa 100644 --- a/cinema/views.py +++ b/cinema/views.py @@ -29,12 +29,10 @@ def get(self, request: Request) -> Response: def post(self, request: Request) -> Response: serializer = GenreSerializer(data=request.data) - if serializer.is_valid(): + if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - class GenreDetail(APIView): def get_object(self, pk: int) -> Genre: @@ -49,21 +47,17 @@ def get(self, request: Request, pk: int) -> Response: def put(self, request: Request, pk: int) -> Response: genre = self.get_object(pk) serializer = GenreSerializer(genre, data=request.data) - if serializer.is_valid(): + if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - def patch(self, request: Request, pk: int) -> Response: genre = self.get_object(pk) serializer = GenreSerializer(genre, data=request.data, partial=True) - if serializer.is_valid(): + if serializer.is_valid(raise_exception=True): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - def delete(self, request: Request, pk: int) -> Response: genre = self.get_object(pk) genre.delete()