我需要从授权客户端获得响应,客户端有一个令牌来从API请求书籍,所以我的代码如下;
class BooksViewSet(viewsets.ModelViewSet):
permission_classes = [TokenHasScope]
required_scopes = ['books']
这里我需要知道要求哪些书籍进行查询并向客户返回一个响应,我该怎么知道?
答案 0 :(得分:0)
你可以像这样覆盖get_queryset
:
class BooksViewSet(viewsets.ModelViewSet):
permission_classes = [TokenHasScope]
required_scopes = ['books']
def get_queryset(self):
# Replace this queryset with the books you want to query for.
# You can use self.request to access parameters.
return Book.objects.all()