Код: Выделить всё
Class Table():
main_option_1: Any
main_option_2: Any
class ExtraOption():
extra_option: Any
class TableExtraOption():
table_id: FK
extra_option_id: FK
value: Any
Фильтры хранятся как:
Код: Выделить всё
class CategoryOfTable():
name: str
class FilterCategory():
option: str (it maybe both main option and extra option)
category_id: FK
order: int (order of that uses frontend to show filter)
Я прочитал несколько вопросов на stackoverflow и решил использовать схему pydantic для параметров запроса следующим образом:
Код: Выделить всё
class ExtraOptionValueQuerySchema(BaseModel):
name: Optional[str] = None
class ExtraOptionQuerySchema(BaseModel):
name: Optional[str] = None
item: Optional[List[ExtraOptionValueQuerySchema]] = Depends()
class RecordQuerySchema(BaseModel):
length_gt: Optional[float] = None
length_lt: Optional[float] = None
width_gt: Optional[float] = None
width_lt: Optional[float] = None
height_gt: Optional[float] = None
height_lt: Optional[float] = None
weight_gt: Optional[float] = None
weight_lt: Optional[float] = None
brand: Optional[str] = None
extra_options: Optional[List[ExtraOptionQuerySchema]] = Depends()
@app.get("")
async def get_records(
category_id: uuid_pkg.UUID, request: Request, query: RecordQuerySchema = Depends(), db: AsyncSession = Depends(get_db)
) -> None:
pass
Подробнее здесь: https://stackoverflow.com/questions/786 ... parameters