Files
pydantic/docs/examples/field_order.py
T
Samuel Colvin 33b7d52d31 moving docs to mkdocs (#856)
* moving docs to mkdocs

* transfering readme to md and more

* fixing build

* splitting usage.md

* improving schema.md and index.md

* fix make_history.rst

* models intro

* working on data conversation and required fields

* more fixes to models.md

* list all standard types supported

* list of pydantic types

* tweaks

* update links in code

* Apply suggestions from code review

incorporate @dmontagu's suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more missed suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more corrects.

* cleanup

* Field order warning

* fix and regenerate benchmarks

* format examples better, cleanup

* improve schema mapping table

* correct highlighting file types in schema.md

* add redirects in javascript

* add logo
2019-10-07 17:19:01 +01:00

23 lines
481 B
Python

from pydantic import BaseModel, ValidationError
class Model(BaseModel):
a: int
b = 2
c: int = 1
d = 0
e: float
print(Model.__fields__.keys())
#> dict_keys(['a', 'c', 'e', 'b', 'd'])
m = Model(e=2, a=1)
print(m.dict())
#> {'a': 1, 'c': 'x', 'e': 2.0, 'b': 2, 'd': 'y'}
try:
Model(a='x', b='x', c='x', d='x', e='x')
except ValidationError as e:
error_logs = [e['loc'] for e in e.errors()]
print(error_logs)
#> [('a',), ('c',), ('e',), ('b',), ('d',)]