-
I've my pydantic model and i want to use on UseAdditionalFields, like this CustomPage = CustomizedPage[
Page[T],
UseAdditionalFields(
extra=MyCustomModel
),
] |
Beta Was this translation helpful? Give feedback.
Answered by
uriyyo
Jan 29, 2025
Replies: 2 comments 2 replies
-
I’ve noticed one thing: using add_pagination(app) works, but I’m not using it. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi @Kavan72, You actually need to use Here is working example: from typing import TypeVar
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi_pagination import Page, add_pagination, paginate
from fastapi_pagination.customization import CustomizedPage, UseAdditionalFields
app = FastAPI()
add_pagination(app)
T = TypeVar("T")
class UserCount(BaseModel):
active: int
invited: int
banned: int
rejected: int
CustomPage = CustomizedPage[
Page[T],
UseAdditionalFields(
extra=UserCount,
),
]
@app.get("/nums")
async def get_nums(is_admin: bool = False) -> CustomPage[int]:
return paginate(
range(1_000),
additional_data={
"extra": UserCount(active=1, banned=2, rejected=3, invited=4),
}
) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Kavan72
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Kavan72,
You actually need to use
add_pagination
, without it code will not work.Here is working example: