Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
TsvetanKichuk committed Sep 28, 2024
1 parent 151c0d1 commit 6b352db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cinema/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
17 changes: 14 additions & 3 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,24 @@ 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()
return Response(status=status.HTTP_204_NO_CONTENT)


class ActorList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView,
):
queryset = Actor.objects.all()
serializer_class = ActorSerializer
Expand All @@ -68,7 +78,6 @@ class ActorDetail(
mixins.DestroyModelMixin,
generics.GenericAPIView,
):

queryset = Actor.objects.all()
serializer_class = ActorSerializer

Expand All @@ -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)

Expand All @@ -90,7 +102,6 @@ class CinemaHallViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):

queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer

Expand Down

0 comments on commit 6b352db

Please sign in to comment.