From 27c705668c39135b70a62cca91e70a84b498739a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 17 Jan 2024 11:19:32 -0500 Subject: [PATCH] membershipworks: Slightly simplify admin task "last run time" logic --- membershipworks/admin.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/membershipworks/admin.py b/membershipworks/admin.py index 6625946..a2477dd 100644 --- a/membershipworks/admin.py +++ b/membershipworks/admin.py @@ -36,14 +36,14 @@ class BaseMembershipWorksAdmin(DjangoObjectActions, ReadOnlyAdmin): def _get_tool_dict(self, tool_name): tool = super(DjangoObjectActions, self)._get_tool_dict(tool_name) if tool_name == "refresh_membershipworks_data": - last_run = ( - Task.objects.filter(group="Scrape Data from MembershipWorks") - .order_by("started") - .last() - ) - last_run_time = ( - naturaltime(last_run.started) if last_run is not None else "Never" - ) + try: + last_run_time = naturaltime( + Task.objects.filter(group="Scrape Data from MembershipWorks") + .values_list("started", flat=True) + .latest("started") + ) + except Task.DoesNotExist: + last_run_time = "Never" tool["label"] = f"Refresh Data [Last Run {last_run_time}]" return tool