Skip to content

Amount of entries in each page #295

Answered by uriyyo
nareto asked this question in Q&A
Mar 23, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @nareto,

Sorry for the long response.

You can create your own Page class.

If you want fixed page size:

from typing import TypeVar, Literal, Generic

from fastapi import Query

from fastapi_pagination import Page as BasePage, Params as BaseParams

T = TypeVar("T")


class Params(BaseParams):
    size: Literal[50] = Query(50, description="Page size")


class Page(BasePage[T], Generic[T]):
    __params_type__ = Params

If you want custom constraints page size:

from typing import TypeVar

from fastapi import Query

from fastapi_pagination import Page as BasePage, Params as BaseParams

T = TypeVar("T")


class Params(BaseParams):
    size: int = Query(10, ge=1, le=10, description="Page size")…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by uriyyo
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