-
Notifications
You must be signed in to change notification settings - Fork 723
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 #707
base: master
Are you sure you want to change the base?
Solution #707
Conversation
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.
Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the handling of ManyToMany fields in the create
and update
methods of the MovieSerializer
needs correction, and the put
method in GenreDetail
is missing a call to serializer.save()
. Once these are fixed, your code will be in great shape! Keep up the great work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
movies.set(actors) | ||
movies.set(genres) |
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.
There is an error in the create method. The correct method to add ManyToMany relationships is to use 'set' on the related manager, e.g., 'movies.actors.set(actors)' and 'movies.genres.set(genres)'. The current code attempts to call 'set' directly on the Movie instance, which is incorrect.
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.genres = validated_data.get("genres", instance.genres) |
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.
In the update method, directly assigning ManyToMany fields like 'instance.genres = ...' is incorrect. Instead, use 'instance.genres.set(genres)' to update the ManyToMany relationships.
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) |
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.
In the put method of GenreDetail, the serializer's save method is missing after checking if the serializer is valid. You should call 'serializer.save()' before returning the response with the serialized data.
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.
Great work on implementing the models, migrations, serializers, and views! 🎉 There are a couple of critical issues that need attention: in the MovieSerializer
, ensure you call the set
method on the actors
and genres
fields, and in the GenreDetail
view, remember to call serializer.save()
to persist updates. These improvements will enhance your code's functionality. Keep up the good work and continue learning from these experiences!
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
movies.set(actors) | ||
movies.set(genres) |
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.
There is an error here. The 'set' method should be called on the ManyToMany fields 'actors' and 'genres', not directly on the 'movies' instance. You should use 'movies.actors.set(actors)' and 'movies.genres.set(genres)'.
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST) |
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.
In the put method of GenreDetail, the serializer's save method is missing. You need to call 'serializer.save()' before returning the response to ensure that the updates are saved to the database.
No description provided.