From 20448bc587fbd4fe2190dd453ded829111da14db Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 12 Jun 2023 15:13:29 +0200 Subject: [PATCH] improved relationships --- app/orm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/orm.py b/app/orm.py index 587b8d6..f395498 100644 --- a/app/orm.py +++ b/app/orm.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from sqlalchemy import Column, VARCHAR, CHAR, ForeignKey, DATETIME, update, and_, inspect, text, BLOB, INT, FLOAT from sqlalchemy.engine import Engine -from sqlalchemy.orm import sessionmaker, declarative_base, Session +from sqlalchemy.orm import sessionmaker, declarative_base, Session, relationship from app.util import parse_key @@ -58,6 +58,8 @@ class Instance(Base): lease_renewal_period = Column(FLOAT(precision=2), nullable=False, default=DEFAULT_LEASE_RENEWAL_PERIOD) client_token_expire_delta = Column(INT(), nullable=False, default=DEFAULT_CLIENT_TOKEN_EXPIRE_DELTA, comment='in seconds') + __origin = relationship(Site, foreign_keys=[site_key]) + def __str__(self): return f'INSTANCE_REF: {self.instance_ref} (SITE_KEY_XID: {self.site_key})' @@ -197,6 +199,9 @@ class Lease(Base): lease_expires = Column(DATETIME(), nullable=False) lease_updated = Column(DATETIME(), nullable=False) + __instance = relationship(Instance, foreign_keys=[instance_ref]) + __origin = relationship(Origin, foreign_keys=[origin_ref]) + def __repr__(self): return f'Lease(origin_ref={self.origin_ref}, lease_ref={self.lease_ref}, expires={self.lease_expires})'