1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| class Test(BaseModel): name: str description: int created_at: str updated_at: str data: dict
@validator("data", pre=True) def parse_data(cls, value): return json.loads(value) if value else {}
@validator("created_at", pre=True) def parse_created_at(cls, value): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(value)))
@validator("updated_at", pre=True) def parse_updated_at(cls, value): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(value)))
class Config: orm_mode = True schema_extra = { "example": { "name": "Foo", "description": "A very nice Item", "created_at": "", "updated_at": "", "data": {} } }
|