Remove reduntant property last

Fixes #38
This commit is contained in:
Lukáš Kucharczyk 2023-01-18 16:52:40 +01:00
parent 2760068cde
commit 8e4086ce83
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
2 changed files with 3 additions and 5 deletions

View File

@ -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

View File

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