Skip to content

Wrap paginated data #1375

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

You must be logged in to vote

Hi @kamilos956,

I guess the esiest way will be smth like this:

from typing import TypeVar, Any

from pydantic import computed_field

from fastapi_pagination import Page

T = TypeVar("T")


class CustomPage(Page[T]):
    __model_exclude__ = {
        "total",
        "page",
        "size",
        "pages",
    }

    @computed_field
    def pagination(self) -> dict[str, Any]:
        return {
            "total": self.total,
            "page": self.page,
            "size": self.size,
            "pages": self.pages,
        }
from fastapi_pagination import paginate, set_page, set_params, Params

set_page(CustomPage[int])
set_params(Params(page=2, size=2))
page = paginate(range(200))

print

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kamilos956
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