Python 3.x 在ListApiView中的url_路径之前筛选pk。德扬戈

Python 3.x 在ListApiView中的url_路径之前筛选pk。德扬戈,python-3.x,django,django-rest-framework,Python 3.x,Django,Django Rest Framework,我有urlpatterns+=[path('collection//video/',CollectionVideoViewSet.as_view(),name='collection-videos')] 和ListAPIView: class CollectionVideoViewSet(ListAPIView): """ViewSet for operation with videos in collection"""

我有
urlpatterns+=[path('collection//video/',CollectionVideoViewSet.as_view(),name='collection-videos')]

ListAPIView

class CollectionVideoViewSet(ListAPIView):

    """ViewSet for operation with videos in collection"""
    permission_classes = (IsAuthenticated,)
    queryset = Video.objects.all()
    serializer_class = CollectionVideoSerializer
我可以通过
pk
筛选此视图中的查询集吗


因此,我想在输出数据中有count,next,previous字段,覆盖get\u querysetListAPIView的方法

class TeamList(generics.ListAPIView):
    serializer_class = TeamSerializer

    def get_queryset(self, *args, **kwargs):
        sc = EmployeeSearchCriteria(email=self.kwargs["email"], role=Employee.VIEWER)
        return EmployeeCalculatorService().get_team_by_employee(sc)

您需要重写
get\u queryset
方法:

class CollectionVideoViewSet(ListAPIView):
“”“用于对集合中的视频进行操作的视图集”“”
权限\类=(已验证,)
queryset=Video.objects.all()
serializer\u class=CollectionVideoSerializer
def get_queryset(自我):
#假设您的“视频”模型与“收藏”有多对一关系`
返回self.queryset.filter(
collection\uuu pk=self.kwargs['pk']
)
为了使视图返回分页结果,即count、next、previous,您需要在视图中定义一个
pagination_类

来自rest_framework.pagination导入PageNumberPagination
类CollectionVideoViewSet(ListAPIView):
分页\u类=页码分页

关于DRF的更多信息在这种情况下,我会在返回的信息中有count,next,previous字段吗?是的,它是通过不同的方法完成的,您不会覆盖这些方法