Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Created September 30, 2016 09:49
Show Gist options
  • Save andreagrandi/14e07afd293fafaea770f69cf66cac14 to your computer and use it in GitHub Desktop.
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
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
@edrisranjbar
Copy link

this code snippet was so helpful. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment