https://github.com/rhyslwells/ML_Tools/blob/main/Explorations/Utilities/Pydantic_More.py
Key Features Demonstrated in the Script:
- Nested Models: Use of the
Friend
model inside theUser
model. - Custom Validators: Validating
age
andemail
fields with specific logic. - Dynamic Defaults: Using
datetime.now
forcreated_at
. - Field Aliases: Supporting different key names during parsing and serialization.
- Configuration Options: Stripping whitespace and enabling strict typing.
- Model Inheritance: Extending the
User
model to create anAdminUser
model. - Parsing Raw Data: Demonstrating
parse_raw
for JSON strings.