  
  
  class BasicObjectPermWithDetail(permissions.BasePermission):
      message = 'Custom: You cannot access this resource'
  
      def has_object_permission(self, request, view, obj):
          return False
  
  
 
</s> remove                     request, message=getattr(permission, 'message', None)
 </s> add                     request,
                    message=getattr(permission, 'message', None),
                    code=getattr(permission, 'code', None) </s> remove                     request, message=getattr(permission, 'message', None)
 </s> add                     request,
                    message=getattr(permission, 'message', None),
                    code=getattr(permission, 'code', None)
    code = 'permission_denied_custom'
  
  
  class BasicObjectPermWithDetail(permissions.BasePermission):
      message = 'Custom: You cannot access this resource'
    code = 'permission_denied_custom'
  
      def has_object_permission(self, request, view, obj):
          return False
  
  
keep keep keep add keep keep keep keep keep
 Pass custom code to PermissionDenied if permission class had one set (#7306) 
tests/test_permissions.py