Esempio n. 1
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    owner = db.relationship('User', backref=db.backref('creater', lazy=True))

    article_id = db.Column(db.Integer, db.ForeignKey('article.id'))
    article = db.relationship('Article',
                              backref=db.backref('article', lazy=True))

    def __repr__(self):
        return '<Comment %r' % self.id
Esempio n. 2
0
class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(32), nullable=False)

    message_id = db.Column(db.Integer,
                           db.ForeignKey('message.id'),
                           nullable=False)
    message = db.relationship('Message', backref=db.backref('tags', lazy=True))
Esempio n. 3
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False)
    cut = db.Column(db.String(128), nullable=False)
    text = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    owner_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    owner = db.relationship('User', backref=db.backref('owner', lazy=True))

    tags = db.relationship('Tag',
                           secondary=tags,
                           lazy='subquery',
                           backref=db.backref('articles', lazy=True))

    comments = db.relationship('Comment',
                               lazy=True,
                               backref=db.backref('comments', lazy=True))

    def __repr__(self):
        return '<Article %r>' % self.id