Djnago rest framework how to allow only update user own content only

I don’t want to allow any user to update another user’s object. I want to allow only update user’s own content only. here is my code:

models.py

class Blog(models.Model):
    author = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True)
    blog_title = models.CharField(max_length=200, unique=True)

views.py

class BlogViewSet(viewsets.ModelViewSet):
    queryset = Blog.objects.all()
    serializer_class = BlogSerializer
    pagination_class = BlogPagination
    lookup_field = 'blog_slug'
    

    def update(self, request, slug=None):
        pass

How can I overwrite the update method? I tried somethings like this but didn’t work:

def update(self, instance, validated_data):
        request = self.context.get("request")
        if instance.author.id == request.user.id:
            instance.save()

How did that “not work”? Did you get an error message? Did it allow for an edit by someone other than the author? What specifically went wrong?

You show a BlogViewSet class, and then in a separate block of text you show an update method. Is that update method supposed to be the update method in the BlogViewSet or a method in a different view?