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": {}
}
}