【发布时间】:2021-01-12 23:49:35
【问题描述】:
我想通过提供 URL 参数来过滤我的 ModelViewSet。所以,例如:
class WidgetViewSet(ModelViewSet):
queryset = Widget.objects.all()
serializer_class = WidgetSerializer
def get_queryset(self):
return Widget.objects.filter(id=id) # id would be a url param
假设我 ping /widgets/43。这将使用id=43 过滤Widgets。我该怎么做?
【问题讨论】: