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"))