From b3842504afb9f25883231602c75af70cc8992dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 4 Jan 2023 17:25:19 +0100 Subject: [PATCH] Save calculated duration to database --- CHANGELOG.md | 1 + src/web/tracker/models.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac4a6f..82f52b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ * Set default version to "git-main" to indicate development environment * Add homepage, link to it from the logo * Make it possible to add a new platform +* Save calculated duration to database if both timestamps are set diff --git a/src/web/tracker/models.py b/src/web/tracker/models.py index 06da9b9..50db664 100644 --- a/src/web/tracker/models.py +++ b/src/web/tracker/models.py @@ -52,3 +52,8 @@ class Session(models.Model): if self.duration_manual == None else self.duration_manual + self.calculated_duration() ) + + def save(self, *args, **kwargs): + if self.timestamp_start != None and self.timestamp_end != None: + self.duration_calculated = self.timestamp_end - self.timestamp_start + super(Session, self).save(*args, **kwargs)