From f053f4456f40d56273f14dba6e75501bd81e7e98 Mon Sep 17 00:00:00 2001 From: Marc Koch Date: Mon, 14 Jul 2025 19:52:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20improve=20list=20display=20of=20?= =?UTF-8?q?calendars=20amd=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhances the calendar admin interface by adding more relevant fields to the list display, such as associated users, auto-clearing settings, and the email template used. Also improves the event admin by including calendar, creation date, start, and end times to the list display, and orders events by calendar in addition to start and end times. --- src/booking.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/booking.py b/src/booking.py index 689edaa..6946a33 100644 --- a/src/booking.py +++ b/src/booking.py @@ -102,7 +102,10 @@ class EmailTemplate(models.Model): return self.name -@app.admin +@app.admin( + list_display=("name", "all_users", "auto_clear_bookings", + "auto_clear_overlap_horizon_days", "email_template"), + list_filter=("auto_clear_bookings",)) class Calendar(models.Model): """ A calendar model to store events. @@ -137,8 +140,18 @@ class Calendar(models.Model): def __str__(self): return self.name + def all_users(self) -> str: + """ + Get the users of the calendar. + It's kind of inefficient, but in small databases it should be fine. + :return: A list of users. + """ + return ", ".join([u.username for u in self.users.all()]) -@app.admin(ordering=("start", "end", "name"), list_filter=("cancelled",)) + +@app.admin(ordering=("start", "end", "calendar", "name"), + list_filter=("cancelled",), + list_display=("name", "calendar", "created", "start", "end")) class Event(models.Model): """ Event model to store events in a calendar and send them to a CalDAV server. @@ -230,8 +243,7 @@ class Event(models.Model): return shortuuid.decode(self.id.__str__()) def __str__(self): - string = f"{self.id} - {self.name} - ({self.start:%Y-%m-%d %H:%M} - {self.end:%Y-%m-%d %H:%M})" - return string if not self.cancelled else f"{string} - CANCELLED" + return self.name @app.admin(