diff --git a/fet2020/core/admin.py b/fet2020/core/admin.py index 1679847d..b8493871 100644 --- a/fet2020/core/admin.py +++ b/fet2020/core/admin.py @@ -36,6 +36,49 @@ class CustomFlatPageAdmin(FlatPageAdmin): list_filter = ("registration_required",) +# Set the ordering of models in Admin Dashboard +def get_app_list(self, request): + """ + Return a sorted list of all the installed apps that have been + registered in this site. + """ + # Retrieve the original list + app_dict = self._build_app_dict(request) + app_list = sorted(app_dict.values(), key=lambda x: x["name"].lower()) + + # Sort the models customably within each app. + for app in app_list: + if app["app_label"] == "intern": + ordering = { + "Themenbereiche": 1, + "Themen": 2, + "Anhang Ordner": 3, + "Etherpads": 4, + "Dateien": 5, + } + app["models"].sort(key=lambda x: ordering[x["name"]]) + + elif app["app_label"] == "members": + ordering = { + "Mitglieder": 1, + "Tätigkeitsbereiche": 2, + "Tätigkeiten": 3, + } + app["models"].sort(key=lambda x: ordering[x["name"]]) + + elif app["app_label"] == "posts": + ordering = { + "News": 1, + "Events": 2, + "Fet Sitzungen": 3, + } + app["models"].sort(key=lambda x: ordering[x["name"]]) + + return app_list + + +admin.AdminSite.get_app_list = get_app_list + # Customise the Django Admin admin.site.index_title = "FET" admin.site.site_header = "Admin" diff --git a/fet2020/intern/models.py b/fet2020/intern/models.py index 3e77131f..e9cd223e 100644 --- a/fet2020/intern/models.py +++ b/fet2020/intern/models.py @@ -32,7 +32,7 @@ class TopicGroup(models.Model): class Meta: verbose_name = "Themenbereich" # "1." because this point should be displayed first in admin view. - verbose_name_plural = "1. Themenbereiche" + verbose_name_plural = "Themenbereiche" def __str__(self): return self.title @@ -66,7 +66,7 @@ class Topic(models.Model): class Meta: verbose_name = "Thema" - verbose_name_plural = "2. Themen" + verbose_name_plural = "Themen" def __str__(self): return self.title @@ -93,7 +93,7 @@ class Attachment(models.Model): class Meta: verbose_name = "Anhang Ordner" - verbose_name_plural = "3. Anhang Ordner" + verbose_name_plural = "Anhang Ordner" constraints = [ UniqueConstraint(fields=["slug", "topic"], name="unique_intern_slug_topic"),