How to define parameters(page, filter fields, etc) automatically to the list_route URL similar to "page" in list()?

23 views
Skip to first unread message

sarvi

unread,
May 9, 2017, 10:39:21 AM5/9/17
to Django REST framework


I am having trouble figuring out how to automatically add page and filter fields to list_route URL
I already have the regular "list" action, from modelviewset working, and it automatically supports the page, and filter_fields defined as parameters to the list URL

What I would like to do is to define a list_detail URL through the list_route(), with "automatic" support for page and filter fields similar the list() action. 
So I modeled the code in list_detail() method to be exactly the same as the list() method in ListViewSet mixin.
My goal is add a DetailedSerializer to list_detail so it lists more details than list() action.

Any ideas how to do this ?

class MirrorVolumeViewSet(views.ModelViewSet):

    permission_classes = (permissions.IsAuthenticated,)

    queryset = MirrorVolume.objects.all()

    serializer_class = volserializers.MirrorVolumeSerializer

    filter_fields = ('volume', 'srcvolume')


    @list_route()

    def list_detail(self, request, *args, **kwargs):

        '''Get list with details '''

        queryset = self.filter_queryset(self.get_queryset())


        page = self.paginate_queryset(queryset)

        if page is not None:

            serializer = self.get_serializer(page, many=True)

            return self.get_paginated_response(serializer.data)


        serializer = self.get_serializer(queryset, many=True)

        return Response(serializer.data)

#        return super(MirrorVolumeViewSet, self).list(request, *args, **kwargs)



Thanks,

Sarvi

sarvi

unread,
May 9, 2017, 4:25:05 PM5/9/17
to Django REST framework
Think this has more to do with schema generation.
pagination and other params are not being added into the schemas.py:is_list_view() not treating the list_route() views as list views.

probably a bug?
Reply all
Reply to author
Forward
0 new messages