Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
9rosLove committed Oct 10, 2023
1 parent 202db2b commit 5ae71a3
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5ae71a3

Please sign in to comment.