Created
April 17, 2015 08:24
-
-
Save Kobold/c5ead2b72b2be03eb0ca to your computer and use it in GitHub Desktop.
IsOwner - Custom django-rest-framework permission to only allow owners of an object to edit it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import permissions | |
class IsOwner(permissions.BasePermission): | |
""" | |
Custom permission to only allow owners of an object to edit it. | |
""" | |
def has_permission(self, request, view): | |
return request.user and request.user.is_authenticated() | |
def has_object_permission(self, request, view, obj): | |
return obj.user == request.user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For this, you must edit your ViewSet. Like this exemplo, only the owner of the product can view it.