class Task(Base): task_id = db.Column(db.Integer, primary_key=True) task_title = db.Column(db.String(200), unique=False) task_detail = db.Column(db.Text, unique=False) deadline = db.Column(db.DATETIME, nullable=True) archived = db.Column(db.DateTime) is_archived = db.Column(db.Boolean, default=False) task_group_id = db.Column(db.Integer, db.ForeignKey('task_group.task_group_id')) task_status_id = db.Column(db.Integer, db.ForeignKey('task_status.task_status_id')) # One-to-One relation task_group: TaskGroup = db.relationship('TaskGroup', backref='Task', lazy=True) # One-to-One relation task_status: TaskStatus = db.relationship('TaskStatus', backref='Task', lazy=True) def __repr__(self): return '<Task %r, %s>' % (self.task_id, self.title)
class UserGroup(Base): user_group_id = db.Column(db.Integer, primary_key=True) user_group_name = db.Column(db.String(200), unique=False) # Many-to-Many relation users = db.relationship('User', secondary=user_group_rel, lazy='subquery', backref=db.backref('UserGroup', lazy=True)) # One-to-Many relation task_groups = db.relationship('TaskGroup', backref='UserGroup', lazy=True)
class User(Base): user_id = db.Column(db.Integer, primary_key=True) e_mail = db.Column(db.String(256), unique=True) # Many-to-Many relation user_groups = db.relationship('UserGroup', secondary=user_group_rel, lazy='subquery', backref=db.backref('User', lazy=True))
class TaskGroup(Base): task_group_id = db.Column(db.Integer, primary_key=True) task_group_title = db.Column(db.String(200), unique=False) user_group_id = db.Column(db.Integer, db.ForeignKey('user_group.user_group_id')) archived = db.Column(db.DateTime) is_archived = db.Column(db.Boolean, default=False) # One-to-Many relation tasks = db.relationship('Task', backref='TaskGroup', lazy=True) # One-to-One relation user_group = db.relationship('UserGroup', backref='TaskGroup', lazy=True) # One-to-Many relation task_statuses = db.relationship('TaskStatus', backref='TaskGroup', lazy=True)
class TaskStatus(Base): task_status_id = db.Column(db.Integer, primary_key=True) task_status_name = db.Column(db.String(200), unique=False) is_done = db.Column(db.Boolean) task_group_id = db.Column(db.Integer, db.ForeignKey('task_group.task_group_id')) # One-to-One relation task_group: TaskGroup = db.relationship('TaskGroup', backref='TaskStatus', lazy=True) def __init__(self, task_status_name, is_done, task_group_id): self.task_status_name = task_status_name self.is_done = is_done self.task_group_id = task_group_id