Created
July 14, 2014 00:01
-
-
Save sprite2005/60b129326f9fbe5daa37 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 IsOwnerOrReadOnly(permissions.BasePermission): | |
""" | |
Custom permission to only allow owners of an object to edit it. | |
""" | |
def has_object_permission(self, request, view, obj): | |
# Read permissions are allowed to any request, | |
# so we'll always allow GEt, HEAD or OPTIONS requests. | |
if request.method in permissions.SAFE_METHODS: | |
return True | |
# Write permissions are only allowed to the owner of the snippet | |
return obj.owner == request.user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment