From 716d8a766ae0c4e2539f2df601269a3203bcd715 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 16 Nov 2022 23:00:10 -0700 Subject: Show post images --- activities/views/posts.py | 4 +++- activities/views/timelines.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'activities/views') diff --git a/activities/views/posts.py b/activities/views/posts.py index 3ee35cc..7b93e42 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -36,7 +36,9 @@ class Like(View): def post(self, request, handle, post_id): identity = by_handle_or_404(self.request, handle, local=False) - post = get_object_or_404(identity.posts, pk=post_id) + post = get_object_or_404( + identity.posts.prefetch_related("attachments"), pk=post_id + ) if self.undo: # Undo any likes on the post for interaction in PostInteraction.objects.filter( diff --git a/activities/views/timelines.py b/activities/views/timelines.py index 45a0c30..ae01a45 100644 --- a/activities/views/timelines.py +++ b/activities/views/timelines.py @@ -39,6 +39,7 @@ class Home(FormView): type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost], ) .select_related("subject_post", "subject_post__author") + .prefetch_related("subject_post__attachments") .order_by("-created")[:100] ) context["interactions"] = PostInteraction.get_event_interactions( @@ -66,6 +67,7 @@ class Local(TemplateView): context["posts"] = ( Post.objects.filter(visibility=Post.Visibilities.public, author__local=True) .select_related("author") + .prefetch_related("attachments") .order_by("-created")[:100] ) context["current_page"] = "local" @@ -82,6 +84,7 @@ class Federated(TemplateView): context["posts"] = ( Post.objects.filter(visibility=Post.Visibilities.public) .select_related("author") + .prefetch_related("attachments") .order_by("-created")[:100] ) context["current_page"] = "federated" -- cgit v1.2.3