mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
82ef45c890
* fix iteration to not convert to dict by default * add change * remove extra newline
22 lines
474 B
Python
22 lines
474 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.dict())
|
|
# (returns a dictionary)
|
|
# > {'banana': 3.14, 'foo': 'hello', 'bar': {'whatever': 123}}
|
|
|
|
print(m.dict(include={'foo', 'bar'}))
|
|
# > {'foo': 'hello', 'bar': {'whatever': 123}}
|
|
|
|
print(m.dict(exclude={'foo', 'bar'}))
|
|
# > {'banana': 3.14}
|