...

/

Updating and Deleting a Comment

Updating and Deleting a Comment

Learn to implement the functionality to update and delete comments in our application.

Updating a comment is an action that can only be done by the author of the comment. And the user should only be able to update the body field of the comment and can’t modify the author value. Let's go over the steps to add the update feature.

In core/comment/viewsets, make sure that put is in the list of http_method_names of CommentViewSet:

Press + to interact
class CommentViewSet(AbstractViewSet):
http_method_names = ('post', 'get', 'put', 'delete')

Validating post

After that, let’s write a validate method for the post field. We want to make sure that this value is not editable on PUT requests.

Inside the core/comment/serializers.py ...