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