mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
e7227db41a
* 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
16 lines
338 B
Python
16 lines
338 B
Python
from datetime import datetime
|
|
|
|
from pydantic import validator
|
|
from pydantic.dataclasses import dataclass
|
|
|
|
@dataclass
|
|
class DemoDataclass:
|
|
ts: datetime = None
|
|
|
|
@validator('ts', pre=True, always=True)
|
|
def set_ts_now(cls, v):
|
|
return v or datetime.now()
|
|
|
|
print(DemoDataclass())
|
|
print(DemoDataclass(ts='2017-11-08T14:00'))
|