[Answered ]-In django-rest-framework, how can I have a resource that is only editable by the user that created it?

2👍

Create a permission that your modelviewset uses

class CreatorPermissions(BasePermission):
    def has_permission(self, request, view):
        return request.method in permissions.SAFE_METHOD

    def has_object_permission(self, request, view, obj):
        return request.user.id == obj.user.id

class ImageViewSet(viewsets.ModelViewSet):
    model = Image
    serializer_class = ImageSerializer # you have to create this
    permission_classes = (CreatorPermissions,)
    queryset = Image.objects.all() 

Leave a comment