mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
17b5ff42c1
* renaming docs examples * tweaks
22 lines
544 B
Python
22 lines
544 B
Python
from pydantic import BaseModel
|
|
|
|
class Voice(BaseModel):
|
|
name: str
|
|
language_code: str
|
|
|
|
class Config:
|
|
@classmethod
|
|
def alias_generator(cls, string: str) -> str:
|
|
# this is the same as `alias_generator = to_camel` above
|
|
return ''.join(word.capitalize() for word in string.split('_'))
|
|
|
|
class Character(Voice):
|
|
mood: str
|
|
|
|
class Config:
|
|
fields = {'mood': 'Mood', 'language_code': 'lang'}
|
|
|
|
c = Character(Mood='happy', Name='Filiz', lang='tr-TR')
|
|
print(c)
|
|
print(c.dict(by_alias=True))
|