Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
markus2812 committed Nov 3, 2023
1 parent feb6f22 commit cfce442
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cinema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
class Genre(models.Model):
name = models.CharField(max_length=255, unique=True)

def __str__(self):
def __str__(self) -> str:
return self.name


class Actor(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)

def __str__(self):
def __str__(self) -> str:
return f"{self.first_name} {self.last_name}"


Expand All @@ -21,7 +21,7 @@ class CinemaHall(models.Model):
rows = models.IntegerField()
seats_in_row = models.IntegerField()

def __str__(self):
def __str__(self) -> str:
return self.name


Expand All @@ -38,5 +38,5 @@ class Movie(models.Model):
)
duration = models.IntegerField()

def __str__(self):
def __str__(self) -> str:
return self.title
16 changes: 8 additions & 8 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class MovieSerializer(serializers.Serializer):
queryset=Genre.objects.all()
)

def create(self, validated_data):
def create(self, validated_data) -> Movie:
actors_data = validated_data.pop("actors")
genres_data = validated_data.pop("genres")
movie = Movie.objects.create(**validated_data)
movie.actors.set(actors_data)
movie.genres.set(genres_data)
return movie

def update(self, instance, validated_data):
def update(self, instance, validated_data) -> Movie:
instance.title = validated_data.get(
"title",
instance.title
Expand Down Expand Up @@ -56,10 +56,10 @@ class GenreSerializer(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
name = serializers.CharField(max_length=255)

def create(self, validated_data):
def create(self, validated_data) -> Genre:
return Genre.objects.create(**validated_data)

def update(self, instance, validated_data):
def update(self, instance, validated_data) -> Genre:
instance.name = validated_data.get(
"name",
instance.name
Expand All @@ -73,10 +73,10 @@ class ActorSerializer(serializers.Serializer):
first_name = serializers.CharField(max_length=255)
last_name = serializers.CharField(max_length=255)

def create(self, validated_data):
def create(self, validated_data) -> Actor:
return Actor.objects.create(**validated_data)

def update(self, instance, validated_data):
def update(self, instance, validated_data) -> Actor:
instance.first_name = validated_data.get(
"first_name",
instance.first_name
Expand All @@ -95,10 +95,10 @@ class CinemaHallSerializer(serializers.Serializer):
rows = serializers.IntegerField()
seats_in_row = serializers.IntegerField()

def create(self, validated_data):
def create(self, validated_data) -> CinemaHall:
return CinemaHall.objects.create(**validated_data)

def update(self, instance, validated_data):
def update(self, instance, validated_data) -> CinemaHall:
instance.name = validated_data.get(
"name",
instance.name
Expand Down

0 comments on commit cfce442

Please sign in to comment.