model: minor convention updates
This commit is contained in:
parent
0cb3966de6
commit
2ed10a5a9d
|
@ -19,7 +19,8 @@ class Forum(db.Model):
|
|||
parent = db.relationship('Forum', backref='sub_forums', remote_side=id,
|
||||
lazy=True, foreign_keys=parent_id)
|
||||
|
||||
# Also [topics] which is provided by a backref from the Topic class
|
||||
# Other fields populated automatically through relations:
|
||||
# <topics> List of topics in this exact forum (of type Topic)
|
||||
|
||||
def __init__(self, url, name, prefix, descr="", parent=None):
|
||||
self.url = url
|
||||
|
@ -32,9 +33,9 @@ class Forum(db.Model):
|
|||
else:
|
||||
self.parent = parent
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Forum: {self.name}>'
|
||||
|
||||
def post_count(self):
|
||||
"""Number of posts in every topic of the forum, without subforums."""
|
||||
return sum(len(t.thread.comments) for t in self.topics)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Forum: {self.name}>'
|
||||
|
|
|
@ -11,13 +11,14 @@ class Notification(db.Model):
|
|||
href = db.Column(db.UnicodeText)
|
||||
date = db.Column(db.DateTime, default=datetime.now())
|
||||
|
||||
owner_id = db.Column(db.Integer, db.ForeignKey('member.id'), nullable=False)
|
||||
owner_id = db.Column(db.Integer, db.ForeignKey('member.id'),nullable=False)
|
||||
owner = db.relationship('Member', backref='notifications',
|
||||
foreign_keys=owner_id)
|
||||
|
||||
def __init__(self, owner_id, text, href=None):
|
||||
""" Check weather or not the id is valid before creating the notif! """
|
||||
def __init__(self, owner, text, href=None):
|
||||
self.text = text
|
||||
self.href = href
|
||||
self.owner_id = owner_id
|
||||
self.owner = owner
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Notification to {self.owner.name}: {self.text} ({self.href})>'
|
||||
|
|
|
@ -79,7 +79,7 @@ GroupMember = db.Table('group_member', db.Model.metadata,
|
|||
db.Column('uid', db.Integer, db.ForeignKey('member.id')))
|
||||
|
||||
|
||||
# Meny-to-many relationship for privileges granted to groups
|
||||
# Many-to-many relationship for privileges granted to groups
|
||||
class GroupPrivilege(db.Model):
|
||||
__tablename__ = 'group_privilege'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
|
|
@ -12,7 +12,8 @@ class Thread(db.Model):
|
|||
top_comment_id = db.Column(db.Integer, db.ForeignKey('comment.id'))
|
||||
top_comment = db.relationship('Comment', foreign_keys=top_comment_id)
|
||||
|
||||
# Also a relation [comments] populated from the Comment class.
|
||||
# Other fields populated automatically through relations:
|
||||
# <comments> The list of comments (of type Comment)
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
|
@ -24,8 +25,8 @@ class Thread(db.Model):
|
|||
|
||||
def set_top_comment(self, top_comment):
|
||||
"""
|
||||
Changes the top comment of the thread. The old top comment will become
|
||||
visible in the flow of posts?
|
||||
Changes the top comment of the thread. The old top comment will usually
|
||||
become visible in the flow of posts instead of being pinned at the top.
|
||||
|
||||
Arguments:
|
||||
top_comment -- new top comment, must belong to this thread
|
||||
|
|
|
@ -97,10 +97,12 @@ class Member(User):
|
|||
newsletter = db.Column(db.Boolean, default=False)
|
||||
|
||||
# Relations
|
||||
notifications = db.relationship('Notification', backref="owner", lazy=True)
|
||||
trophies = db.relationship('Trophy', secondary=TrophyMember,
|
||||
back_populates='owners')
|
||||
|
||||
# Other fields populated automatically through relations:
|
||||
# <notifications> List of unseen notifications (of type Notification)
|
||||
|
||||
def __init__(self, name, email, password):
|
||||
"""Register a new user."""
|
||||
self.name = name
|
||||
|
|
Loading…
Reference in New Issue