Skip to content

How to include total for cursor pagination? #960

Answered by uriyyo
holtgrewe asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @holtgrewe,

Currently, you need to define a custom page for this:

from typing import Generic, TypeVar

from fastapi_pagination.bases import CursorRawParams
from fastapi_pagination.cursor import CursorPage, CursorParams

T = TypeVar("T")


class TotalCursorParams(CursorParams):
    def to_raw_params(self) -> CursorRawParams:
        params = super().to_raw_params()
        params.include_total = True

        return params


class TotalCursorPage(CursorPage[T], Generic[T]):
    __params_type__ = TotalCursorParams

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@holtgrewe
Comment options

Answer selected by holtgrewe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants