Ejemplo n.º 1
0
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}')"
Ejemplo n.º 2
0
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}')"
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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}')"
Ejemplo n.º 8
0
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")