diff --git a/app/models/comment.py b/app/models/comment.py index b9e60f2..a27617c 100644 --- a/app/models/comment.py +++ b/app/models/comment.py @@ -1,5 +1,6 @@ from app import db from app.models.post import Post +from sqlalchemy.orm import backref class Comment(Post): __tablename__ = 'comment' @@ -14,7 +15,8 @@ class Comment(Post): # Parent thread thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), nullable=False) - thread = db.relationship('Thread', backref='comments', + thread = db.relationship('Thread', + backref=backref('comments', lazy='dynamic'), foreign_keys=thread_id) def __init__(self, author, text, thread): diff --git a/app/routes/forum/topic.py b/app/routes/forum/topic.py index bf02827..dcebd61 100644 --- a/app/routes/forum/topic.py +++ b/app/routes/forum/topic.py @@ -38,4 +38,12 @@ def forum_topic(f, t): db.session.merge(t) db.session.commit() - return render('/forum/topic.html', t=t, form=form) + if request.args.get('page') == "last": + page = t.thread.comments.count() // V5Config.COMMENTS_PER_PAGE + 1 + else: + page = request.args.get('page', 1, type=int) + + comments = t.thread.comments.paginate(page, + V5Config.COMMENTS_PER_PAGE, True) + + return render('/forum/topic.html', t=t, form=form, comments=comments) diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 456b34d..0008d36 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -15,7 +15,7 @@
{{ widget_member.profile(c.author ) }} | @@ -27,7 +27,7 @@ {% endif %}