mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
docs linting and improving first example
This commit is contained in:
+4
-2
@@ -1,14 +1,16 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
|
||||
class UserModel(BaseModel):
|
||||
id: int = ...
|
||||
name = 'John Doe'
|
||||
signup_ts: datetime = None
|
||||
friends: List[int] = []
|
||||
|
||||
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22'}
|
||||
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
|
||||
user = UserModel(**external_data)
|
||||
print(user)
|
||||
# > UserModel id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22)
|
||||
# > UserModel id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
|
||||
print(user.id)
|
||||
# > 123
|
||||
|
||||
Reference in New Issue
Block a user