class ViewTwo(APIView):
permission_classes = (permissions.IsBar,)
class ViewThree(ViewTwo):
permission_classes = (permissions.IsXYZ,)
ViewThree
如何继承ViewTwo
权限才能同时拥有permissions.IsBar
和permissions.IsXYZ
权限类?
答案 0 :(得分:2)
我想,您需要在get_permissions
中实现ViewThree
方法,该方法实例化并返回此视图所需的权限列表:
class ViewThree(ViewTwo):
def get_permissions(self):
return super().get_permissions() + (permissions.IsXYZ,)
答案 1 :(得分:0)
通过追加ViewTwo的权限来简单地定义ViewThree的权限。
class ViewTwo(TemplateView):
permission_classes = (permissions.IsBar,)
class ViewThree(ViewTwo):
permission_classes = ViewTwo.permission_classes + (permissions.IsXYZ,)