feat(admin): Add fields to the user admin panel

This commit is contained in:
Tom Hubrecht 2024-09-27 12:41:02 +02:00
parent dc8f89be86
commit c7e13b76f2
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
3 changed files with 60 additions and 4 deletions

View file

@ -1,6 +1,7 @@
from allauth.socialaccount.models import SocialAccount, SocialApp, SocialToken
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.utils.translation import gettext_lazy as _
from import_export.admin import ImportExportMixin
from unfold.admin import ModelAdmin
from unfold.contrib.import_export.forms import (
@ -11,6 +12,8 @@ from unfold.contrib.import_export.forms import (
from dgsi.models import Bylaws, Service, Statutes, Translation, User
assert DjangoUserAdmin.fieldsets is not None
# Unregister allauth models
def unregister(*models, site=None):
@ -36,11 +39,20 @@ unregister(SocialAccount, SocialApp, SocialToken)
@admin.register(User)
class UserAdmin(BaseUserAdmin, ImportExportMixin, ModelAdmin):
class UserAdmin(DjangoUserAdmin, ImportExportMixin, ModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
export_form_class = SelectableFieldsExportForm
# Add the local fields
fieldsets = (
*DjangoUserAdmin.fieldsets,
(
_("Documents DGNum"),
{"fields": ("accepted_statutes", "accepted_bylaws")},
),
)
@admin.register(Bylaws, Service, SocialAccount, Statutes, Translation)
class AdminClass(ImportExportMixin, ModelAdmin):

View file

@ -0,0 +1,36 @@
# Generated by Django 4.2.16 on 2024-09-27 10:40
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("dgsi", "0006_translation"),
]
operations = [
migrations.AlterField(
model_name="user",
name="accepted_bylaws",
field=models.ForeignKey(
default=None,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="dgsi.bylaws",
verbose_name="Dernier Règlement Intérieur accepté",
),
),
migrations.AlterField(
model_name="user",
name="accepted_statutes",
field=models.ForeignKey(
default=None,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="dgsi.statutes",
verbose_name="Derniers statuts acceptés",
),
),
]

View file

@ -139,10 +139,18 @@ class User(AbstractUser):
"""
accepted_statutes = models.ForeignKey(
Statutes, on_delete=models.SET_NULL, null=True, default=None
Statutes,
on_delete=models.SET_NULL,
null=True,
default=None,
verbose_name=_("Derniers statuts acceptés"),
)
accepted_bylaws = models.ForeignKey(
Bylaws, on_delete=models.SET_NULL, null=True, default=None
Bylaws,
on_delete=models.SET_NULL,
null=True,
default=None,
verbose_name=_("Dernier Règlement Intérieur accepté"),
)
# accepted_terms = models.ManyToManyField(TermsAndConditions)