diff --git a/app/models/forum.py b/app/models/forum.py index 71d2381..acc2fff 100644 --- a/app/models/forum.py +++ b/app/models/forum.py @@ -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: + # 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'' - 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'' diff --git a/app/models/notification.py b/app/models/notification.py index f2830e8..7ace4fa 100644 --- a/app/models/notification.py +++ b/app/models/notification.py @@ -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'' diff --git a/app/models/privs.py b/app/models/privs.py index 223629e..426f755 100644 --- a/app/models/privs.py +++ b/app/models/privs.py @@ -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) diff --git a/app/models/thread.py b/app/models/thread.py index ab3eb74..bd1236b 100644 --- a/app/models/thread.py +++ b/app/models/thread.py @@ -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: + # 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 diff --git a/app/models/users.py b/app/models/users.py index 55516dd..80da7e1 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -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: + # List of unseen notifications (of type Notification) + def __init__(self, name, email, password): """Register a new user.""" self.name = name