Make the "Finish now?" button on session list work

This commit is contained in:
2023-01-04 19:19:49 +01:00
parent 61d2e65d83
commit 6fe960bc04
9 changed files with 32 additions and 26 deletions

View File

@ -1,5 +1,7 @@
from django.db import models
from datetime import timedelta
from datetime import datetime
from django.conf import settings
from zoneinfo import ZoneInfo
class Game(models.Model):
@ -40,6 +42,9 @@ class Session(models.Model):
mark = ", manual" if self.duration_manual != None else ""
return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_any()}{mark})"
def finish_now(self):
self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
def duration_seconds(self):
if self.timestamp_end == None or self.timestamp_start == None:
if self.duration_manual == None: