Files
pydantic/docs/examples/exporting_models_exclude1.py
T
Stephen Brown II 13b002e97f Add datetime field to default_factory example (#1301)
* Add change file

* Add datetime field to default_factory example

Print instead of assert
Remove bad quotes
Remove bad quotes from all examples

* fix change description

* remove 'avoid-escape' from setup.cfg

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-18 20:23:42 +00:00

30 lines
552 B
Python

from pydantic import BaseModel, SecretStr
class User(BaseModel):
id: int
username: str
password: SecretStr
class Transaction(BaseModel):
id: str
user: User
value: int
t = Transaction(
id='1234567890',
user=User(
id=42,
username='JohnDoe',
password='hashedpassword'
),
value=9876543210
)
# using a set:
print(t.dict(exclude={'user', 'value'}))
# using a dict:
print(t.dict(exclude={'user': {'username', 'password'}, 'value': ...}))
print(t.dict(include={'id': ..., 'user': {'id'}}))