Files
pydantic/docs/examples/alias_generator_config.py
T
Arseny Boykov 010ba38dc1 Add alias_generator (#622)
* Added alias_provider

* Update HISTORY.rst (+ add alias_provider support #622 by @MrMrRobat)

* Rename alias_provider —> alias_generator
Move docs to config section, reformat example
Separate test_alias_generator

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Fix conflict between dictionary field config in Config.fields and Config.alias_generator

Add one more condition for applying alias_generator

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Add test for using alias_generator with field schema
2019-07-02 12:13:06 +01:00

22 lines
472 B
Python

from pydantic import BaseModel
def to_camel(string: str) -> str:
return ''.join(word.capitalize() for word in string.split('_'))
class Voice(BaseModel):
name: str
gender: str
language_code: str
class Config:
alias_generator = to_camel
voice = Voice(Name='Filiz', Gender='Female', LanguageCode='tr-TR')
print(voice.language_code)
print(voice.dict(by_alias=True))
"""
tr-TR
{'Name': 'Filiz', 'Gender': 'Female', 'LanguageCode': 'tr-TR'}
"""