From 8e4086ce83b257b19f033fecd38c740afb0ea927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 18 Jan 2023 16:52:40 +0100 Subject: [PATCH] Remove reduntant property last Fixes #38 --- src/web/tracker/models.py | 4 ---- src/web/tracker/views.py | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index c393c35..b469141 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -79,10 +79,6 @@ class Session(models.Model): def duration_sum(self) -> str: return Session.objects.all().total_duration() - @property - def last(self) -> Manager[Any]: - return Session.objects.all().order_by("timestamp_start")[0] - def save(self, *args, **kwargs): if self.timestamp_start != None and self.timestamp_end != None: self.duration_calculated = self.timestamp_end - self.timestamp_start diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index f12157c..9274716 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -66,6 +66,7 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", game_id="" dataset = Session.objects.filter(purchase__game=game_id) context["game"] = Game.objects.get(id=game_id) else: + # by default, sort from newest to oldest dataset = Session.objects.all().order_by("-timestamp_start") for session in dataset: @@ -75,7 +76,8 @@ def list_sessions(request, filter="", purchase_id="", platform_id="", game_id="" context["total_duration"] = dataset.total_duration() context["dataset"] = dataset - context["last"] = Session.objects.all().last() + # cannot use dataset[0] here because that might be only partial QuerySet + context["last"] = Session.objects.all().order_by("timestamp_start").last() # charts are always oldest->newest context["chart"] = playtime_over_time_chart(dataset.order_by("timestamp_start"))