Deleting and Updating Posts

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

We'll cover the following

Another important feature is allowing users to delete or update posts. Let’s see how we can add this with Django.

To add these functionalities, we don’t need to write a serializer or a viewset, because the methods for deletion (destroy()), and updating (update()) are already available by default in the ViewSet class. We will just rewrite the update method on PostSerializer to ensure that the edited field is set to True when modifying a post.

Let’s add the PUT and DELETE methods to http_methods of PostViewSet:

Get hands-on with 1400+ tech skills courses.