diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -87,8 +87,7 @@ class Thread(models.Model): if reply_count > 0: reply_count_to_show = min(settings.LAST_REPLIES_COUNT, reply_count - 1) - replies = self.replies.order_by('pub_time').defer( - 'poster_user_agent', 'text_markup_type') + replies = self.get_replies() last_replies = replies[reply_count - reply_count_to_show:] return last_replies @@ -107,7 +106,7 @@ class Thread(models.Model): Gets sorted thread posts """ - query = self.replies.order_by('pub_time') + query = self.replies.order_by('pub_time').prefetch_related('images') if view_fields_only: query = query.defer('poster_user_agent', 'text_markup_type') return query.all() @@ -161,4 +160,4 @@ class Thread(models.Model): Gets opening post's pub time because thread does not have its own one. """ - return self.get_opening_post().pub_time \ No newline at end of file + return self.get_opening_post().pub_time 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 @@ -47,7 +47,7 @@ {% endif %} {% if post.images.exists %} - {% with post.get_first_image as image %} + {% with post.images.all.0 as image %}