Created
September 30, 2016 09:49
-
-
Save andreagrandi/14e07afd293fafaea770f69cf66cac14 to your computer and use it in GitHub Desktop.
IsAdminOrReadOnly is a custom Django Rest Framework permission class that allows Admin users to POST and anonymous to GET
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.permissions import BasePermission, SAFE_METHODS | |
class IsAdminOrReadOnly(BasePermission): | |
def has_permission(self, request, view): | |
if request.method in SAFE_METHODS: | |
return True | |
else: | |
return request.user.is_staff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this code snippet was so helpful. Thanks a lot.