mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
f55515820a
* renaming .json -> .model_dump_json * renaming .dict -> .model_dump * renaming .__fields__ -> .model_fields * renaming .schema -> .model_json_schema * renaming .construct -> .model_construct * renaming .parse_obj -> .model_validate * make linters happy * add changes md-file Co-authored-by: Samuel Colvin <s@muelcolvin.com>
30 lines
515 B
Python
30 lines
515 B
Python
from pydantic import BaseModel, Field, SecretStr
|
|
|
|
|
|
class User(BaseModel):
|
|
id: int
|
|
username: str
|
|
password: SecretStr = Field(..., exclude=True)
|
|
|
|
|
|
class Transaction(BaseModel):
|
|
id: str
|
|
user: User = Field(..., exclude={'username'})
|
|
value: int
|
|
|
|
class Config:
|
|
fields = {'value': {'exclude': True}}
|
|
|
|
|
|
t = Transaction(
|
|
id='1234567890',
|
|
user=User(
|
|
id=42,
|
|
username='JohnDoe',
|
|
password='hashedpassword'
|
|
),
|
|
value=9876543210,
|
|
)
|
|
|
|
print(t.model_dump())
|