diff --git a/forum/models.py b/forum/models.py index f7c4a481..3b3d73a1 100644 --- a/forum/models.py +++ b/forum/models.py @@ -116,10 +116,8 @@ class Forum(models.Model): last_msg = None for m in ForumMessage.objects.select_related('topic__forum', 'author').order_by('-id'): forum = m.topic.forum - if self in (forum.parent_list + [forum]): + if self in (forum.parent_list + [forum]) and not m.deleted: return m - last_msg = m - return last_msg class ForumTopic(models.Model): forum = models.ForeignKey(Forum, related_name='topics') @@ -151,6 +149,12 @@ class ForumTopic(models.Model): except: return None + @cached_property + def last_message(self): + for msg in self.messages.order_by('id').select_related('author').order_by('-id').all(): + if not msg.deleted: + return msg + @property def title(self): return self.messages.order_by('date').first().title diff --git a/forum/templates/forum/macros.jinja b/forum/templates/forum/macros.jinja index 88163e9f..a0f48e21 100644 --- a/forum/templates/forum/macros.jinja +++ b/forum/templates/forum/macros.jinja @@ -67,11 +67,13 @@