-
FastAPIWrapper(
root_url="/courses/",
fastapi_app=app,
piccolo_crud=PiccoloCRUD(
table=Course,
read_only=False,
schema_extra={
"deserialize_json": True
}
),
fastapi_kwargs=FastAPIKwargs(
all_routes={"tags": ["courses"]},
),
) How can i |
Beta Was this translation helpful? Give feedback.
Answered by
sinisaos
May 22, 2023
Replies: 1 comment 2 replies
-
@hoosnick This is currently not possible, but perhaps we can add class PiccoloCRUD(Router):
"""
Wraps a Piccolo table with CRUD methods for use in a REST API.
"""
max_page_size: int = 1000
def __init__(
...
deserialize_json: bool = False, # or some other name
) -> None:
self.deserialize_json = deserialize_json
def _pydantic_model_output(
self,
include_readable: bool = False,
include_columns: t.Tuple[Column, ...] = (),
nested: t.Union[bool, t.Tuple[Column, ...]] = False,
) -> t.Type[pydantic.BaseModel]:
return create_pydantic_model(
...
deserialize_json=self.deserialize_json,
)
def pydantic_model_plural(
self,
include_readable=False,
include_columns: t.Tuple[Column, ...] = (),
nested: t.Union[bool, t.Tuple[Column, ...]] = False,
):
base_model: t.Any = create_pydantic_model(
...
deserialize_json=self.deserialize_json,
)
return pydantic.create_model(
str(self.table.__name__) + "Plural",
__config__=Config,
rows=(t.List[base_model], None),
) Usage then will be FastAPIWrapper(
root_url="/courses/",
fastapi_app=app,
piccolo_crud=PiccoloCRUD(
table=Course,
read_only=False,
deserialize_json=True,
),
fastapi_kwargs=FastAPIKwargs(
all_routes={"tags": ["courses"]},
),
) @dantownsend What do you think about that? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hoosnick Yes of course. You can create two separate models and routes for it, like in the piccolo asgi template. In out model you can pass
deserialize_json=True
like thisHope that helps.