Skip to content

Instantly share code, notes, and snippets.

@tomchristie
Created January 23, 2013 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchristie/4608048 to your computer and use it in GitHub Desktop.
Save tomchristie/4608048 to your computer and use it in GitHub Desktop.
class IsOwner(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_permission(self, request, view, obj=None):
# Skip the check unless this is an object-level test
if obj is None:
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