Browse Source

Merge pull request #266 from justanr/ISSUE-223-internal-error-when-deleting-reporting-post

Fixes #223 Deleting Flagged Post causes 500 INTERNAL SERVER ERROR - tentative fix
Peter Justin 8 years ago
parent
commit
8e37fe6862
1 changed files with 5 additions and 3 deletions
  1. 5 3
      flaskbb/forum/models.py

+ 5 - 3
flaskbb/forum/models.py

@@ -98,7 +98,10 @@ class Report(db.Model, CRUDMixin):
     zapped_by = db.Column(db.Integer, db.ForeignKey("users.id"))
     reason = db.Column(db.Text)
 
-    post = db.relationship("Post", backref="report", lazy="joined")
+    post = db.relationship(
+        "Post", lazy="joined",
+        backref=db.backref('report', cascade='all, delete-orphan')
+    )
     reporter = db.relationship("User", lazy="joined",
                                foreign_keys=[reporter_id])
     zapper = db.relationship("User", lazy="joined", foreign_keys=[zapped_by])
@@ -339,14 +342,13 @@ class Topic(db.Model, CRUDMixin):
 
         # If the topic is unread try to get the first unread post
         if topic_is_unread(self, topicsread, user, forumsread):
-            # 
             query = Post.query.filter(Post.topic_id == self.id)
             if topicsread is not None:
                 query = query.filter(Post.date_created > topicsread.last_read)
             post = query.order_by(Post.id.asc()).first()
             if post is not None:
                 return post.url
-        
+
         return self.url
 
     # Methods