Files
pydantic/docs/examples/export_copy.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

20 lines
522 B
Python

from pydantic import BaseModel
class BarModel(BaseModel):
whatever: int
class FooBarModel(BaseModel):
banana: float
foo: str
bar: BarModel
m = FooBarModel(banana=3.14, foo='hello', bar={'whatever': 123})
print(m.copy(include={'foo', 'bar'}))
print(m.copy(exclude={'foo', 'bar'}))
print(m.copy(update={'banana': 0}))
print(id(m.bar), id(m.copy().bar))
# normal copy gives the same object reference for `bar`
print(id(m.bar), id(m.copy(deep=True).bar))
# deep copy gives a new object reference for `bar`