class Vote(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False) vote = db.Column(db.Boolean, nullable=False) def __repr__(self): return f"Comment('{self.id}', '{self.user_id}', '{self.post_id}', {self.vote}')"
class Moderator(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), nullable=False) def __repr__(self): return f"Moderator('{self.id}', '{self.user_id}', '{self.thread_id}')"
class Message(db.Model): id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, db.ForeignKey('user.id')) recipient_id = db.Column(db.Integer, db.ForeignKey('user.id')) title = db.Column(db.String(100), nullable=False) body = db.Column(db.Text, nullable=False) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) def __repr__(self): return '<Message {}>'.format(self.body)
class Rule(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) title = db.Column(db.String(100), nullable=False) date_created = db.Column(db.DateTime, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), nullable=False)
class Notification(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), index=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) timestamp = db.Column(db.Float, index=True, default=time) payload_json = db.Column(db.Text) def get_data(self): return json.loads(str(self.payload_json))
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) date_posted = db.Column(db.DateTime, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False) votes = db.relationship('CommentVote', backref='votes', lazy=True, cascade="all, delete-orphan") def __repr__(self): return f"Comment('{self.title}', '{self.date_posted}')" def delete_post(self, comment_id): com = Comment.query().filter(comment_id) db.session.delete(com)
class Post(db.Model): __tablename__ = 'post' __searchable__ = ['title', 'content'] __analyzer__ = StemmingAnalyzer() id = db.Column(db.Integer, primary_key=True, nullable=False) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) date_posted = db.Column(db.DateTime, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), nullable=True) comments = db.relationship('Comment', backref='comment', lazy=True, cascade="all, delete-orphan") votes = db.relationship('Vote', backref='votes', lazy=True, cascade="all, delete-orphan") def __repr__(self): return f"Post('{self.title}','{self.content} '{self.date_posted}')"
class Thread(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) description = db.Column(db.Text, nullable=False) date_created = db.Column(db.DateTime, default=datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) moderator = db.relationship('Moderator', backref='moderator_id', lazy=True, cascade="all, delete-orphan") rule = db.relationship('Rule', backref='rule', lazy=True, cascade="all, delete-orphan") posts = db.relationship('Post', backref='posts', lazy=True, cascade="all, delete-orphan")