Files
Fulfillment-Backend/schemas/base.py
2024-04-11 14:25:40 +03:00

41 lines
889 B
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