class CommentModel(db.Model): comment_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) post_id = db.Column(db.Integer, db.ForeignKey(PostModel.post_id), nullable=True) user_id = db.Column(db.Integer, db.ForeignKey(UserModel.user_id), nullable=False) parent_id = db.Column(db.Integer) comment_text = db.Column(db.String, nullable=False) created_time = db.Column(db.DateTime(timezone=True), default=func.now()) points = db.relationship("CommentPointModel", backref='comments', cascade='delete') def __init__(self, user_id, post_id, comment_text, parent_id): self.comment_text = comment_text self.user_id = user_id self.post_id = post_id self.parent_id = parent_id self.created_time = datetime.utcnow() self.modified_at = datetime.utcnow()
class UserRolesModel(db.Model): user_role_id = db.Column(db.Integer(), primary_key=True, autoincrement=True) user_id = db.Column(db.Integer(), db.ForeignKey(UserModel.user_id), unique=True) role_id = db.Column(db.Integer(), db.ForeignKey(RoleModel.role_id)) def __init__(self, user_id, role_id): self.user_id = user_id self.role_id = role_id
class File(db.Model): id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(100), unique=False, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return '<Post %r>' % self.id
class PostPointModel(db.Model): def __init__(self, user_id, post_id, points): self.user_id = user_id self.post_id = post_id self.points = points user_id = db.Column(db.Integer, db.ForeignKey(UserModel.user_id), unique=False, nullable=False) post_id = db.Column(db.Integer, db.ForeignKey(PostModel.post_id), unique=False, nullable=False) point_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) points = db.Column(db.Integer, nullable=False)
class CommentPointModel(db.Model): def __init__(self, comment_id, points): self.comment_id = comment_id self.points = points comment_id = db.Column(db.Integer, db.ForeignKey(CommentModel.comment_id), unique=False, nullable=False) point_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True) points = db.Column(db.Integer, nullable=False)