From 5ae71a3b858b1b9efe4bcfd5ba8b5d306ae38c87 Mon Sep 17 00:00:00 2001 From: Yaroslav Skrypchenko Date: Tue, 10 Oct 2023 18:40:49 +0300 Subject: [PATCH] Solution --- cinema/serializers.py | 53 ------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/cinema/serializers.py b/cinema/serializers.py index ba371b4ba..52d6b32c7 100644 --- a/cinema/serializers.py +++ b/cinema/serializers.py @@ -8,73 +8,20 @@ class Meta: model = Movie fields = ["id", "title", "description", "duration"] - def create(self, validated_data): - return Movie.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.title = validated_data.get("title", instance.title) - instance.description = validated_data.get( - "description", instance.description - ) - instance.duration = validated_data.get("duration", instance.duration) - - instance.save() - - return instance - class ActorSerializer(serializers.ModelSerializer): class Meta: model = Actor fields = "__all__" - def create(self, validated_data): - return Actor.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.first_name = validated_data.get( - "first_name", instance.first_name - ) - instance.last_name = validated_data.get( - "last_name", instance.last_name - ) - - instance.save() - - return instance - class GenreSerializer(serializers.ModelSerializer): class Meta: model = Genre fields = "__all__" - def create(self, validated_data): - return Genre.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.name = validated_data.get("name", instance.name) - - instance.save() - - return instance - class CinemaHallSerializer(serializers.ModelSerializer): class Meta: model = CinemaHall fields = "__all__" - - def create(self, validated_data): - return CinemaHall.objects.create(**validated_data) - - def update(self, instance, validated_data): - instance.name = validated_data.get("name", instance.name) - instance.rows = validated_data.get("rows", instance.rows) - instance.seats_in_row = validated_data.get( - "seats_in_row", instance.seats_in_row - ) - - instance.save() - - return instance