Start sessions of last purchase from list
All checks were successful
continuous-integration/drone/push Build is passing

Fixes #19
This commit is contained in:
2023-01-13 16:54:24 +01:00
parent d8ece979a8
commit 465d958d9b
6 changed files with 30 additions and 4 deletions

View File

@ -4,6 +4,8 @@ from django.conf import settings
from zoneinfo import ZoneInfo
from common.util.time import format_duration
from django.db.models import Sum, F
from django.db.models import Manager
from typing import Any
class Game(models.Model):
@ -57,6 +59,9 @@ class Session(models.Model):
def finish_now(self):
self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
def start_now():
self.timestamp_start = datetime.now(ZoneInfo(settings.TIME_ZONE))
def duration_seconds(self) -> timedelta:
manual = timedelta(0)
calculated = timedelta(0)
@ -74,6 +79,10 @@ 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")[:-1]
def save(self, *args, **kwargs):
if self.timestamp_start != None and self.timestamp_end != None:
self.duration_calculated = self.timestamp_end - self.timestamp_start