From adc6002217ba3afb1504a3a6297b9cfc1b86dffb Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 20 Aug 2022 12:19:54 +0100 Subject: [PATCH] Reuse online accounts query on contact page --- website/contact/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/contact/models.py b/website/contact/models.py index 90e8c65..4591ee9 100644 --- a/website/contact/models.py +++ b/website/contact/models.py @@ -44,14 +44,18 @@ class ContactPage(BaseContentPage): def show_reading_time(self) -> bool: return False + @cached_property + def online_accounts(self) -> models.QuerySet: + return OnlineAccount.objects.all().order_by("name") + @cached_property def table_of_contents(self) -> list[TocEntry]: return [ TocEntry(account.name, account.slug, 0, []) - for account in OnlineAccount.objects.all().order_by("name") + for account in self.online_accounts ] def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) - context["accounts"] = OnlineAccount.objects.all().order_by("name") + context["accounts"] = self.online_accounts return context