Back to writing

Article

Using Pagination and Filters in a ViewSet List Method

Django REST Framework’s filtering and pagination hooks are applied automatically by ListModelMixin.list(). A custom list action should call filter_queryset(), paginate the filtered queryset, serialize the page, and return get_paginated_response(); if no page is produced, serialize the full filtered queryset.

To apply the filter_backends, filterset_class, ordering_fields, serializer_class, and pagination_class attributes to the list method in your View class, you can override the list method and apply the desired behavior