50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
from pydantic import BaseModel
|
|
from pydantic.alias_generators import to_camel
|
|
|
|
|
|
class CustomConfig:
|
|
populate_by_name = True
|
|
from_attributes = True
|
|
|
|
|
|
class CustomModelCamel(BaseModel):
|
|
class Config:
|
|
from_attributes = True
|
|
alias_generator = to_camel
|
|
populate_by_name = True
|
|
|
|
@classmethod
|
|
def from_sql_model(cls, model, fields: dict):
|
|
model_dict = {c.name: getattr(model, c.name) for c in model.__table__.columns}
|
|
model_dict.update(fields)
|
|
return cls(**model_dict)
|
|
|
|
|
|
class CustomModelSnake(BaseModel):
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class OkMessageSchema(CustomModelCamel):
|
|
ok: bool
|
|
message: str
|
|
|
|
|
|
class PaginationSchema(CustomModelCamel):
|
|
page: int | None = None
|
|
items_per_page: int | None = None
|
|
|
|
|
|
class PaginationInfoSchema(CustomModelCamel):
|
|
total_pages: int
|
|
total_items: int
|
|
|
|
|
|
class BaseEnumSchema(CustomModelCamel):
|
|
id: int
|
|
name: str
|
|
|
|
|
|
class BaseEnumListSchema(CustomModelCamel):
|
|
items: list[BaseEnumSchema]
|