PCv5/app/models/topic.py

45 lines
1.3 KiB
Python
Raw Normal View History

2019-08-20 17:34:00 +02:00
from app import db
from app.models.post import Post
from config import V5Config
2019-08-20 17:34:00 +02:00
class Topic(Post):
2019-08-20 17:34:00 +02:00
__tablename__ = 'topic'
__mapper_args__ = {'polymorphic_identity': __tablename__}
# ID of the underlying [Post] object
id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
# Topic title
title = db.Column(db.Unicode(V5Config.THREAD_NAME_MAXLEN))
# Parent forum
2019-08-20 17:34:00 +02:00
forum_id = db.Column(db.Integer, db.ForeignKey('forum.id'), nullable=False)
forum = db.relationship('Forum', backref='topics',foreign_keys=forum_id)
2019-08-20 17:34:00 +02:00
# Associated thread
thread_id = db.Column(db.Integer,db.ForeignKey('thread.id'),nullable=False)
thread = db.relationship('Thread', foreign_keys=thread_id)
# Number of views in the forum
views = db.Column(db.Integer)
def __init__(self, forum, author, title, thread):
"""
Create a Topic.
Arguments:
forum -- parent forum or sub-forum (Forum)
author -- post author (User)
title -- topic title (unicode string)
thread -- discussion thread attached to the topic (Thread)
"""
Post.__init__(self, author)
self.title = title
self.views = 0
self.thread = thread
self.forum = forum
2019-08-20 17:34:00 +02:00
def __repr__(self):
return f'<Topic: #{self.id}>'