diff --git a/.gitignore b/.gitignore index 9c18d6ac5..bbae997be 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ venv/ .pytest_cache/ **__pycache__/ *.pyc -db.sqlite3 \ No newline at end of file +db.sqlite3 diff --git a/cinema/views.py b/cinema/views.py index 7e656d5af..f1262b41c 100644 --- a/cinema/views.py +++ b/cinema/views.py @@ -22,10 +22,9 @@ def get(self, request): def post(self, request): serializer = GenreSerializer(data=request.data) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + serializer.is_valid(raise_exception=True) + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) class GenreDetail(APIView): @@ -43,18 +42,16 @@ def get(self, request, pk): def put(self, request, pk): genre = self.get_object(pk) serializer = GenreSerializer(genre, data=request.data) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data, status=status.HTTP_200_OK) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + serializer.is_valid(raise_exception=True) + serializer.save() + return Response(serializer.data, status=status.HTTP_200_OK) 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, status=status.HTTP_200_OK) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + serializer.is_valid(raise_exception=True) + serializer.save() + return Response(serializer.data, status=status.HTTP_200_OK) def delete(self, request, pk): genre = self.get_object(pk)