mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-23 00:01:16 +00:00
Fix last message when the real last is deleted
This commit is contained in:
parent
9e61b11827
commit
24c02f4638
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user