Files
pydantic/docs/examples/advanced_exclude1.py
T
Samuel Colvin e7227db41a Insert prints in docs. (#895)
* starting insert prints

* working exec_script

* remove prints, fix exec_examples.py

* more cleanup of examples, better model printing

* upgrade netlify runtime

* extra docs deps

* few more small tweaks
2019-10-14 16:40:25 +01: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'}}))