Last active
November 15, 2021 10:19
-
-
Save codemation/a73b24679af81ac7e61292dd127e4198 to your computer and use it in GitHub Desktop.
pydbantic_model_4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
import uuid | |
from datetime import datetime | |
from typing import Optional | |
from pydbantic import DataBaseModel, PrimaryKey, Default | |
def time_now_str(): | |
return datetime.now().isoformat() | |
def stringify_uuid(): | |
return str(uuid.uuid4()) | |
class Positions(DataBaseModel): | |
name: str = PrimaryKey() | |
department: str | |
class Employee(DataBaseModel): | |
id: str = PrimaryKey(default=stringify_uuid) | |
salary: float | |
is_employed: bool | |
date_employed: str = Default(default=time_now_str) | |
position: Positions = Positions(name='Manager', department='HR') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment