from app import db from app.models.post import Post class Comment(Post): __tablename__ = 'comment' __mapper_args__ = {'polymorphic_identity': __tablename__} # ID of the associated Post object id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True) # Standalone properties text = db.Column(db.UnicodeText) # Relations thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), nullable=False) thread = db.relationship('Thread', backref='comments', foreign_keys=thread_id) # attachement = db.relationship('Attachement', backref='comment') def __init__(self, author, text, thread): Post.__init__(author, text) if isinstance(thread, Thread): thread = thread.id self.thread_id = thread