PCv5/app/models/thread.py

32 lines
910 B
Python

from app import db
from app.models.post import Post
from app.models.comment import Comment
from config import V5Config
class Thread(Post):
""" Some thread, such as a topic, program, tutorial """
__tablename__ = 'thread'
id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
thread_type = db.Column(db.String(20))
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': thread_type
}
# Standalone properties
title = db.Column(db.Unicode(V5Config.THREAD_NAME_MAXLEN))
# Relationships
top_comment = db.Column(db.Integer, db.ForeignKey('comment.id'))
comments = db.relationship('Comment', backref='thread')
def __init__(self, author, text, title):
""" Create a Thread """
super.__init__(author, text)
self.title = title
def __repr__(self):
return f'<Thread #{self.id}'