I have dict-like object, like:
data = {
# A lot of data here
'json_data_feed':
{'address':
{'name': 'home_sweet_home'}
}
# A lot of data here
}
And i want to create Pydantic model with few fields. Im trying to do this:
class OfferById(pydantic.BaseModel):
short_address: str = pydantic.Field(..., alias='name')
@pydantic.validator('short_address', pre=True)
def validate_short_address(cls, value):
return value['json_data_feed']['address']
And it fails with exception:
Some = OfferById(**data)
File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for OfferById
name
field required (type=value_error.missing)
Are there any solution here?