Skip to content

0.0.11 - Field Support for Arrays of Foreign DataBase Models

Compare
Choose a tag to compare
@codemation codemation released this 17 Nov 17:02
· 93 commits to main since this release
eab0c57
  • Improved support for foreign model updates, .save() will invoke creation of foreign objects if not existing,
  • Added support for Arrays of Foreign References where a single field in a DataBaseModel may contain a list of other DataBaseModel objects
from uuid import uuid4
from datetime import datetime
from typing import List, Optional
from pydbantic import DataBaseModel, PrimaryKey


def time_now():
    return datetime.now().isoformat()
def get_uuid4():
    return str(uuid4())

class Coordinate(DataBaseModel):
    time: str = PrimaryKey(default=time_now)
    latitude: float
    longitude: float

class Journey(DataBaseModel):
    trip_id: str = PrimaryKey(default=get_uuid4)
    waypoints: List[Optional[Coordinate]]