Set the ordering of models in Admin Dashboard
This commit is contained in:
@@ -36,6 +36,49 @@ class CustomFlatPageAdmin(FlatPageAdmin):
|
|||||||
list_filter = ("registration_required",)
|
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
|
# Customise the Django Admin
|
||||||
admin.site.index_title = "FET"
|
admin.site.index_title = "FET"
|
||||||
admin.site.site_header = "Admin"
|
admin.site.site_header = "Admin"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TopicGroup(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Themenbereich"
|
verbose_name = "Themenbereich"
|
||||||
# "1." because this point should be displayed first in admin view.
|
# "1." because this point should be displayed first in admin view.
|
||||||
verbose_name_plural = "1. Themenbereiche"
|
verbose_name_plural = "Themenbereiche"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@@ -66,7 +66,7 @@ class Topic(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Thema"
|
verbose_name = "Thema"
|
||||||
verbose_name_plural = "2. Themen"
|
verbose_name_plural = "Themen"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@@ -93,7 +93,7 @@ class Attachment(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Anhang Ordner"
|
verbose_name = "Anhang Ordner"
|
||||||
verbose_name_plural = "3. Anhang Ordner"
|
verbose_name_plural = "Anhang Ordner"
|
||||||
|
|
||||||
constraints = [
|
constraints = [
|
||||||
UniqueConstraint(fields=["slug", "topic"], name="unique_intern_slug_topic"),
|
UniqueConstraint(fields=["slug", "topic"], name="unique_intern_slug_topic"),
|
||||||
|
|||||||
Reference in New Issue
Block a user