Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Solution #707

wants to merge 1 commit into from

Conversation

antonver
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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.

Comment on lines +20 to +21
movies.set(actors)
movies.set(genres)

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)

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)

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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! ✨

Comment on lines +20 to +21
movies.set(actors)
movies.set(genres)

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)'.

Comment on lines 39 to +40
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants