💄show duration in event list display

This commit is contained in:
Marc Koch 2025-07-14 20:13:31 +02:00
parent 14dd63ad72
commit e3e9ac3c58
Signed by: marc
GPG Key ID: 12406554CFB028B9
1 changed files with 10 additions and 1 deletions

View File

@ -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