From 3922d659dabe5da23528778a6f8ce77809bea2f9 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Wed, 16 Mar 2022 22:29:34 +0300 Subject: [PATCH] sql_app: models: correct many-to-many relation between iotdev and users Signed-off-by: HeshamTB --- sql_app/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sql_app/models.py b/sql_app/models.py index 46ad3b0..aa4cfd5 100644 --- a/sql_app/models.py +++ b/sql_app/models.py @@ -10,9 +10,10 @@ class User(Base): id = Column(Integer, primary_key=True, index=True) email = Column(String, unique=True, index=True) hashed_password = Column(String) + passwd_salt = Column(String) is_active = Column(Boolean, default=True) - #items = relationship("Item", back_populates="owner") + authorized_devices = relationship("IotEntity", secondary= 'user_iot_link') class IotEntity(Base): @@ -22,4 +23,10 @@ class IotEntity(Base): description = Column(String, index=True) owner_id = Column(Integer, ForeignKey("user_accounts.id")) - #owner = relationship("User", back_populates="items") + authorized_users = relationship("User", secondary= 'user_iot_link') + +class UserAuthToIoTDev(Base): + __tablename__ = "user_iot_link" + + user_id = Column(Integer, ForeignKey('iot_entities.id'), primary_key=True, index=True) + iot_entity_id = Column(Integer, ForeignKey('user_accounts.id'), primary_key=True, index=True)