diff --git a/src/dgsi/admin.py b/src/dgsi/admin.py index f4b8357..29a6911 100644 --- a/src/dgsi/admin.py +++ b/src/dgsi/admin.py @@ -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): diff --git a/src/dgsi/migrations/0007_alter_user_accepted_bylaws_and_more.py b/src/dgsi/migrations/0007_alter_user_accepted_bylaws_and_more.py new file mode 100644 index 0000000..cd203b0 --- /dev/null +++ b/src/dgsi/migrations/0007_alter_user_accepted_bylaws_and_more.py @@ -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", + ), + ), + ] diff --git a/src/dgsi/models.py b/src/dgsi/models.py index 8666680..d2837cb 100644 --- a/src/dgsi/models.py +++ b/src/dgsi/models.py @@ -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)