Created
October 29, 2020 02:22
-
-
Save akkuman/e2cdf463f0a891e318318d66916fc1b4 to your computer and use it in GitHub Desktop.
drf中根据不同的action分发不同的权限
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
class WhiteListViewSet(ModelViewSet): | |
queryset = WhiteList.objects.all() | |
serializer_class = WhiteListSerializer | |
permission_classes = [IsAdminUser] | |
pagination_class = None | |
def get_permissions(self): | |
""" | |
根据不同的action获取不同的权限校验中间件 | |
""" | |
if self.action == 'retrieve' or self.action == 'list': | |
permission_classes = [] | |
else: | |
permission_classes = [IsAdminUser] | |
return [permission() for permission in permission_classes] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment