修复了循环引用的问题
This commit is contained in:
parent
5da049cefb
commit
9aa9d744cf
13
models.py
13
models.py
@ -3,7 +3,7 @@
|
||||
# @Author : 河瞬
|
||||
# @FileName: models.py
|
||||
# @Software: PyCharm
|
||||
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Enum, ForeignKey, Text
|
||||
from sqlalchemy import create_engine, Column, Integer, String, DateTime, ForeignKey, Text
|
||||
from sqlalchemy.orm import relationship, sessionmaker, declarative_base
|
||||
from datetime import datetime
|
||||
|
||||
@ -15,17 +15,18 @@ class Tenant(Base):
|
||||
__tablename__ = 'Tenant'
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
users = relationship('User', backref='Tenant', cascade='all, delete-orphan')
|
||||
projects = relationship('Project', backref='Tenant', cascade='all, delete-orphan')
|
||||
users = relationship('User', back_populates='tenant', cascade='all, delete-orphan')
|
||||
projects = relationship('Project', back_populates='owner', cascade='all, delete-orphan')
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'User'
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
username = Column(String(100), nullable=False)
|
||||
password = Column(String(100), nullable=False)
|
||||
role = Column(Integer, nullable=False) # 0: 超级管理员 1:租户管理员 2:评估员 3:审核员
|
||||
tenant_id = Column(Integer, ForeignKey('Tenant.id'), nullable=False)
|
||||
tenant = relationship('Tenant', back_populates='users')
|
||||
|
||||
|
||||
class Project(Base):
|
||||
@ -36,7 +37,7 @@ class Project(Base):
|
||||
start_time = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
deadline = Column(DateTime, nullable=False)
|
||||
owner_id = Column(Integer, ForeignKey('Tenant.id'), nullable=False)
|
||||
# owner = relationship('Tenant', backref='projects')
|
||||
owner = relationship('Tenant', back_populates='projects')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -47,4 +48,4 @@ if __name__ == "__main__":
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
# 创建会话
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user