From 7c566c853a97288a2e92c2d9be39c0d3e47d4c3b Mon Sep 17 00:00:00 2001 From: Alejandro MG Date: Thu, 31 Oct 2024 16:34:39 +0100 Subject: [PATCH] Improvements on admin legibility --- data/admin/__init__.py | 3 +++ data/admin/declaration.py | 4 +++- data/admin/user.py | 40 ++++++++++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/data/admin/__init__.py b/data/admin/__init__.py index 5592fbaf..fe59fac2 100644 --- a/data/admin/__init__.py +++ b/data/admin/__init__.py @@ -20,6 +20,8 @@ from data.models import PlantPart, PlantFamily from simple_history.admin import SimpleHistoryAdmin +from django.contrib.auth.models import Group + @admin.register(PlantPart) class PlantPartAdmin(SimpleHistoryAdmin): @@ -37,3 +39,4 @@ def get_admin_header(): admin.site.site_header = get_admin_header() admin.site.site_title = get_admin_header() +admin.site.unregister(Group) diff --git a/data/admin/declaration.py b/data/admin/declaration.py index 4942c901..403ca0f5 100644 --- a/data/admin/declaration.py +++ b/data/admin/declaration.py @@ -1,6 +1,8 @@ from django import forms from django.contrib import admin +from simple_history.admin import SimpleHistoryAdmin + from data.models import ( ComputedSubstance, Declaration, @@ -184,7 +186,7 @@ class Meta: @admin.register(Declaration) -class DeclarationAdmin(admin.ModelAdmin): +class DeclarationAdmin(SimpleHistoryAdmin): form = DeclarationForm list_display = ("name", "status", "company", "author") list_filter = ("status", "company", "author") diff --git a/data/admin/user.py b/data/admin/user.py index 465fc4bf..18b8a423 100644 --- a/data/admin/user.py +++ b/data/admin/user.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.contrib.auth import get_user_model from django.contrib.auth.admin import UserAdmin +from django.utils.translation import gettext_lazy as _ from data.models import DeclarantRole, SupervisorRole @@ -23,11 +24,6 @@ class SupervisorRoleInline(admin.TabularInline): @admin.register(get_user_model()) class UserAdmin(UserAdmin): - def __init__(self, model, admin_site): - fieldsets = self.fieldsets[:1] + ((None, {"fields": ("is_verified", "phone_number")}),) + self.fieldsets[1:] - self.fieldsets = fieldsets - super().__init__(model, admin_site) - add_fieldsets = UserAdmin.add_fieldsets + ( (None, {"fields": ("email", "first_name", "last_name", "phone_number")}), ) @@ -43,3 +39,37 @@ def __init__(self, model, admin_site): DeclarantRoleInline, SupervisorRoleInline, ) + + fieldsets = ( + ( + None, + { + "fields": ( + "username", + "password", + "is_verified", + ) + }, + ), + ( + _("Personal info"), + { + "fields": ( + "first_name", + "last_name", + "email", + "phone_number", + ) + }, + ), + ( + _("Permissions"), + { + "fields": ( + "is_active", + "is_staff", + "is_superuser", + ), + }, + ), + )