This commit is contained in:
2024-03-31 07:36:35 +03:00
parent df6e2e7fb1
commit 5de5b9b3e4
12 changed files with 1469 additions and 56 deletions

View File

@@ -1,4 +1,5 @@
from pydantic import BaseModel
from pydantic.alias_generators import to_camel
class CustomConfig:
@@ -6,21 +7,34 @@ class CustomConfig:
from_attributes = True
class CustomModel(BaseModel):
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(BaseModel):
class OkMessageSchema(CustomModelCamel):
ok: bool
message: str
class PaginationSchema(CustomModel):
class PaginationSchema(CustomModelCamel):
page: int
items_per_page: int
class PaginationInfoSchema(CustomModel):
class PaginationInfoSchema(CustomModelCamel):
total_pages: int
total_items: int