-
Notifications
You must be signed in to change notification settings - Fork 722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #393
base: master
Are you sure you want to change the base?
Solution #393
Conversation
def __str__(self) -> str: | ||
return str(self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need here str()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I add an annotation type, and it has an underline without it
def __str__(self) -> str: | ||
return f"{self.name} rows: {self.rows} seats: {self.seats_in_row}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it is more logical to return the name of the hall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree, it depends on the task you have, but here is not business logic about that.
cinema/serializers.py
Outdated
class GenreSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Genre | ||
fields = ["id", "name"] | ||
|
||
|
||
class ActorSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Actor | ||
fields = ["id", "first_name", "last_name"] | ||
|
||
|
||
class CinemaHallSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = CinemaHall | ||
fields = ["id", "name", "rows", "seats_in_row"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use fields = "all"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a good point
cinema/views.py
Outdated
class GenreDetail(APIView): | ||
def get(self, request, pk): | ||
genre = get_object_or_404(Genre, pk=pk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create get_object method, It will be more readable.
cinema/views.py
Outdated
if request.method == "PUT": | ||
serializer = MovieSerializer(movie, data=request.data) | ||
def put(self, request, pk): | ||
genre = get_object_or_404(Genre, pk=pk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
cinema/views.py
Outdated
|
||
def patch(self, request, pk): | ||
genre = get_object_or_404(Genre, pk=pk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and next
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests should pass
I have just pushed that( |
cinema/serializers.py
Outdated
|
||
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) | ||
|
||
actors_data = validated_data.pop("actors", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use an empty list instead of string
No description provided.