💄 improve list display of calendars amd events

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.
This commit is contained in:
Marc Koch 2025-07-14 19:52:51 +02:00
parent 3fa2763ebf
commit f053f4456f
Signed by: marc
GPG Key ID: 12406554CFB028B9
1 changed files with 16 additions and 4 deletions

View File

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