From 86fd40cc4ac5c5aa63d3c14fa54e8c71a741cc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 22 Jul 2024 08:36:36 +0200 Subject: [PATCH] Do not save non-durations as manual --- games/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/games/models.py b/games/models.py index 10335c9..3f5f3e5 100644 --- a/games/models.py +++ b/games/models.py @@ -203,7 +203,7 @@ class Session(models.Model): def duration_seconds(self) -> timedelta: manual = timedelta(0) calculated = timedelta(0) - if self.is_manual(): + if self.is_manual() and isinstance(self.duration_manual, timedelta): manual = self.duration_manual if self.timestamp_end != None and self.timestamp_start != None: calculated = self.timestamp_end - self.timestamp_start @@ -226,6 +226,9 @@ class Session(models.Model): else: self.duration_calculated = timedelta(0) + if not isinstance(self.duration_manual, timedelta): + self.duration_manual = timedelta(0) + if not self.device: default_device, _ = Device.objects.get_or_create( type=Device.UNKNOWN, defaults={"name": "Unknown"}