[Fixed]-Django REST Framework Nested Routers – Pagination not working

1👍

This has nothing to do with routers. Routing is transparent to views, and the only thing they get is a Request object.

You can override ModelViewSet.get_queryset() like this:

class WorkplanMilestones(ModelViewSet):
    #...
    def get_queryset(self):
        wp = get_object_or_404(Workplan, pk=self.kwargs['workplan_pk'])
        return wp.milestones

I am assuming here that the url parameter is called workplan_pk and milestones is the reverse relationship for the milestone model.

This will return workplan’s milestones and the rest (including pagination) is handled by ModelViewSet.

👤Ivan

Leave a comment