Skip to content

Instantly share code, notes, and snippets.

@mmourafiq
Created August 19, 2013 19:13
Show Gist options
  • Save mmourafiq/6272862 to your computer and use it in GitHub Desktop.
Save mmourafiq/6272862 to your computer and use it in GitHub Desktop.
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
if request.method in permissions.SAFE_METHODS:
return True
# Write permissions are only allowed to the owner of the tip
return obj.author == request.user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment