Last active
March 2, 2016 21:32
-
-
Save filipeximenes/b106057309f70214a6a8 to your computer and use it in GitHub Desktop.
Django-rest-framework Permission to simplify per view permission verification
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 CustomViewPermission(permissions.BasePermission): | |
def has_permission(self, request, view): | |
if hasattr(view, 'custom_permission'): | |
return view.custom_permission(request) | |
return True | |
def has_object_permission(self, request, view, obj): | |
if hasattr(view, 'custom_object_permission'): | |
return view.custom_object_permission(request, obj) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment