Created
November 4, 2014 11:15
-
-
Save nferrari/2762af8bf101ed1e077a to your computer and use it in GitHub Desktop.
django-rest-framework read-only permission class
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 IsReadOnly(permissions.BasePermission): | |
""" | |
Object-level permission to only allow read-only operations. | |
""" | |
def has_permission(self, request, view): | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return request.method in permissions.SAFE_METHODS
👍