1.代码
class UserModelSerializer(serializers.ModelSerializer):
role_display = UserRoleSerializer(many=True, source='roles', read_only=True)
class Meta:
model = models.User
fields = ["id", "username", 'password', "is_super", "roles", "role_display"]
class UserView(BaseView, ModelViewSet):
authentication_classes = [JwtAuthentication]
permission_classes = [RbacPermission]
pagination_class = MinePageNumberPagination
queryset = models.User.objects.all().order_by("-id")
serializer_class = UserModelSerializer
@action(detail=False, methods=['get'], url_path="role")
def total_role(self, request):
queryset = models.Role.objects.all()
ser = UserRoleSerializer(instance=queryset, many=True)
return Response(ser.data)
2.settings.py
中
REST_FRAMEWORK = {
"UNAUTHENTICATED_USER": None,
"UNAUTHENTICATED_TOKEN": None,
"EXCEPTION_HANDLER": "utils.view.exception_handler",
"PAGE_SIZE":10
}
标签:分页,示例,models,queryset,role,使用,True,class
From: https://www.cnblogs.com/cloud-2-jane/p/18448669