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: 4 comments 8 replies

Comment options

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

Answer selected by holtgrewe
Comment options

You must be logged in to vote
5 replies
@uriyyo
Comment options

@zromick
Comment options

@uriyyo
Comment options

@zromick
Comment options

@uriyyo
Comment options

Comment options

You must be logged in to vote
2 replies
@uriyyo
Comment options

@zromick
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants