Commit 24c02f46 authored by Skia's avatar Skia

Fix last message when the real last is deleted

parent 9e61b118
Pipeline #884 failed with stage
in 55 seconds
......@@ -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
......
......@@ -67,11 +67,13 @@
</div>
</div>
<div class="ib w_medium" style="text-align: center;">
{% set last_msg = topic.messages.order_by('id').select_related('author').last() %}
{% set last_msg = topic.last_message %}
{% if last_msg %}
{{ user_profile_link(last_msg.author) }} <br/>
<a href="{{ last_msg.get_absolute_url() }}">
{{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
</a>
{% endif %}
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment