Skip to content

How to change name of items field of the Page model? #778

Answered by lelecanfora
lelecanfora asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, that seems easy enough, I ended up creating a class generator and it works as intended:

from typing import Generic, TypeVar, Sequence
from pydantic import Field, ConfigDict
from fastapi_pagination import Page

T = TypeVar("T")

def create_custom_page(items_alias: str):
    class CustomPage(Page[T], Generic[T]):
        items: Sequence[T] = Field(alias=items_alias)
        model_config = ConfigDict(
            **Page.model_config,
            populate_by_name=True
        )
    return CustomPage

Replies: 1 comment 1 reply

Comment options

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

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