【发布时间】:2023-03-15 12:29:01
【问题描述】:
我有 2 个模型,1 个子类化另一个:
from pydantic import BaseModel
from typing import List
class Model1(BaseModel):
names: List[str]
class Model2(Model1):
# define here an alias for names -> e.g. "firstnames"
pass
data = { "names": ["rodrigo", "julien", "matthew", "bob"] }
# Model1(**data).dict() -> gives {'names': ['rodrigo', 'julien', 'matthew', 'bob']}
# Model2(**data).dict() -> gives {'firstnames': ['rodrigo', 'julien', 'matthew', 'bob']}
我怎样才能做到这一点?
【问题讨论】: