From e3e9ac3c584f293c7382decfe22cd0e6b2d13c4b Mon Sep 17 00:00:00 2001 From: Marc Koch Date: Mon, 14 Jul 2025 20:13:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84show=20duration=20in=20event=20list?= =?UTF-8?q?=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/booking.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/booking.py b/src/booking.py index 6946a33..f7daedc 100644 --- a/src/booking.py +++ b/src/booking.py @@ -151,7 +151,8 @@ class Calendar(models.Model): @app.admin(ordering=("start", "end", "calendar", "name"), list_filter=("cancelled",), - list_display=("name", "calendar", "created", "start", "end")) + list_display=("name", "calendar", "created", "duration", "start", + "end")) class Event(models.Model): """ Event model to store events in a calendar and send them to a CalDAV server. @@ -242,6 +243,14 @@ class Event(models.Model): def uuid(self) -> UUID: return shortuuid.decode(self.id.__str__()) + def duration(self) -> str: + """ + Calculate the duration of the event. + :return: The duration in minutes. + """ + duration = (self.end - self.start).total_seconds() // 60 + return f"{duration:.0f}m" + def __str__(self): return self.name