我有一个名为“documentdetailsample”的模型,当你用GET调用它时,类似于这样,GEThttps://url/document-detail-sample/
,那么你就得到了每个“documentdetailsample”。在
模型内部是id,所以,如果您想要每个id,您可以在列表上“迭代”并请求id。在
但是。。。前端开发人员不想这样做:他们说这是太多的工作。。。在
所以,我要把身份证还给你。:天
我在想什么,比如得到https://url/document-detail-sample/id-list
但我不知道如何返回一个列表。我读了this post,我知道如何在后端获取id_列表。但是我不知道我应该实现什么来返回那个url中的列表。。。在
我的观点很简单:
class DocumentDetailSampleViewSet(viewsets.ModelViewSet):
queryset = DocumentDetailSample.objects.all()
serializer_class = DocumentDetailSampleSerializer
网址是这样的:
^{pr2}$所以:
1-使用.../document-detail-sample/id-list"
这样的url是个好主意吗?在
2如果是,我该怎么做?在
3如果没有,我该怎么办?在
您可以使用
@list_route
装饰器此修饰符允许您提供与方法同名的其他端点。
/document-detail-sample/id_list/
reference to docs about extra actions in a viewset
假设不需要分页,只需重写
list
方法,如下所示相关问题 更多 >
编程相关推荐