From ebaecc5ab8624bdfa203846b25b54111f4c3c7f8 Mon Sep 17 00:00:00 2001 From: sabinammm Date: Wed, 16 Mar 2022 14:57:31 +0100 Subject: [PATCH] euth/contrib: overwrite module django admin to redirect to project --- euth/contrib/admin.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 euth/contrib/admin.py diff --git a/euth/contrib/admin.py b/euth/contrib/admin.py new file mode 100644 index 000000000..49272dd93 --- /dev/null +++ b/euth/contrib/admin.py @@ -0,0 +1,36 @@ +from django.contrib import admin +from django.urls import reverse + +from adhocracy4.modules import models +from adhocracy4.phases import admin as phase_admin +from adhocracy4.projects.admin import ProjectAdminFilter + + +class ProjectFilter(ProjectAdminFilter): + project_key = 'module__project' + + +class ItemAdmin(admin.ModelAdmin): + list_filter = ( + 'module__project__organisation', + 'module__project__is_archived', + ProjectFilter + ) + list_display = ('__str__', 'creator', 'created') + readonly_fields = ('creator',) + date_hierarchy = 'created' + + +class ModuleAdmin(admin.ModelAdmin): + inlines = [ + phase_admin.PhaseInline + ] + list_filter = ('project__organisation', 'project') + list_display = ('__str__', 'name') + + def view_on_site(self, obj): + return reverse('project-detail', args=[str(obj.project.slug)]) + + +admin.site.unregister(models.Module) +admin.site.register(models.Module, ModuleAdmin)