Skip to content

rest_framework.documentation lose filter_fields and pagination parameters when using @action #6217

@j4tmr

Description

@j4tmr

Checklist

  • [ 1 ] I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

suppose i have a viewset named BlogViewSet here.

class BlogViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Blog.objects.filter(is_published=True).prefetch_related('tags').order_by('-update_time')
    serializer_class = serializers.BlogSerializer
    pagination_class = StandardResultsSetPagination
    e = ['tags__text', 'language']
    lookup_field = 'uri'

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = serializers.BlogListSerializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = serializers.BlogListSerializer(queryset, many=True)
        return Response(serializer.data)

    @action(detail=False, url_path='uris')
    def uris(self, request):
        uris = list(map(lambda x: {'uri': x.uri, 'date': x.update_time}, self.queryset))
        return Response(uris)

    @action(detail=True)
    def view(self, request, uri):
        plus_blog_visit(uri)
        return Response()

    @action(detail=False)
    def hottest(self, request):
        uris = list(map(lambda x: {'uri': x.uri, 'date': x.update_time}, self.queryset))
        return Response(uris)

I add it to the router and i can successfully visit the different routers of my api. But the docs generated from the rest_framework.documentation is not right.

Expected behavior

I want all the functions in the viewset can be filtered by the parameters i set in the viewset. Such like the filter_fields and pagination backend.

Actual behavior

Actually, i can not filter my customized functions like hottest in the doc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions