diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -140,6 +140,11 @@ class Thread(models.Model): .annotate(images_count=Count( 'attachments')).aggregate(Sum('images_count'))['images_count__sum'] or 0 + @cached_result(key_method=_get_cache_key) + def get_attachment_count(self) -> int: + return self.get_replies().annotate(attachment_count=Count('attachments'))\ + .aggregate(Sum('attachment_count'))['attachment_count__sum'] or 0 + def can_bump(self) -> bool: """ Checks if the thread can be bumped by replying to it. diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -182,7 +182,7 @@ function getReplyCount() { } function getImageCount() { - return $('.thread').find('img').length + return $('.thread').find('.image').length } /** diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -153,7 +153,7 @@
{% endif %} -{% endautoescape %} \ No newline at end of file +{% endautoescape %} diff --git a/boards/templates/boards/thread.html b/boards/templates/boards/thread.html --- a/boards/templates/boards/thread.html +++ b/boards/templates/boards/thread.html @@ -29,8 +29,8 @@ {% with replies_count=thread.get_reply_count%} ♥ {% if thread.has_post_limit %}/{{ thread.max_posts }}{% endif %} {% endwith %} - {% with images_count=thread.get_images_count%} - ❄ {{ images_count }} + {% with attachment_count=thread.get_attachment_count%} + ❄ {{ attachment_count }} {% endwith %} {% trans 'Last update: ' %}