-
-
Save muth0mi/6ac3597666f613a9eddce706b1689bfc 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 hidden or 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