Created
November 15, 2021 11:39
-
-
Save codemation/5b3b0e870ad85e3f46f1f7e67e477c99 to your computer and use it in GitHub Desktop.
pydbantic_model_7.py
This file contains hidden or 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 pydantic import BaseModel | |
from pydbantic import DataBaseModel, PrimaryKey, Default | |
def time_now_str(): | |
return datetime.now().isoformat() | |
def stringify_uuid(): | |
return str(uuid.uuid4()) | |
class Coordinates(BaseModel): | |
latitude: float = 52.299387 | |
longitude: float = 4.976949 | |
class Department(DataBaseModel): | |
name: str = PrimaryKey() | |
company: str | |
location: Optional[Coordinates] = Coordinates() | |
class Positions(DataBaseModel): | |
name: str = PrimaryKey() | |
position_department: Department = Department(name='HR', company='FOOBAR') | |
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment