0

I have a view:

class ProductView(CreateModelMixin, ListModelMixin, GenericViewSet):
    serializer_class = ProductSerializer
    pagination_class = ProductDefaultPagination
    filter_backends = (DjangoFilterBackend, filters.SearchFilter)
    filterset_class = ProductFilter
    search_fields = ["$name"]

It works fine, but I get an error when I'm searching a product by name on the second page (or any other page except the first one). Being on the first page, I can find products from any other pages. Being on page 2, I can't find the product from page 1 or page 3. I get a message "invalid page". How can I solve it?

my pagination.py

from rest_framework import pagination
from rest_framework.response import Response


class ProductDefaultPagination(pagination.PageNumberPagination):
    page_size = 50
    page_size_query_param = "limit"

    def get_paginated_response(self, data):
        return Response(
            {
                "count": self.page.paginator.count,
                "pages": self.page.paginator.num_pages,
                "page": self.page.number,
                "results": data,
            }
        )

Perhaps my command should also set up pagination on the front part of project (Vue, Nuxt). I only do the back-end.

Irina_Xena
  • 245
  • 1
  • 11

0 Answers0