feat(admin): Add fields to the user admin panel
This commit is contained in:
parent
dc8f89be86
commit
c7e13b76f2
3 changed files with 60 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
from allauth.socialaccount.models import SocialAccount, SocialApp, SocialToken
|
from allauth.socialaccount.models import SocialAccount, SocialApp, SocialToken
|
||||||
from django.contrib import admin
|
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 import_export.admin import ImportExportMixin
|
||||||
from unfold.admin import ModelAdmin
|
from unfold.admin import ModelAdmin
|
||||||
from unfold.contrib.import_export.forms import (
|
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
|
from dgsi.models import Bylaws, Service, Statutes, Translation, User
|
||||||
|
|
||||||
|
assert DjangoUserAdmin.fieldsets is not None
|
||||||
|
|
||||||
|
|
||||||
# Unregister allauth models
|
# Unregister allauth models
|
||||||
def unregister(*models, site=None):
|
def unregister(*models, site=None):
|
||||||
|
@ -36,11 +39,20 @@ unregister(SocialAccount, SocialApp, SocialToken)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(User)
|
@admin.register(User)
|
||||||
class UserAdmin(BaseUserAdmin, ImportExportMixin, ModelAdmin):
|
class UserAdmin(DjangoUserAdmin, ImportExportMixin, ModelAdmin):
|
||||||
import_form_class = ImportForm
|
import_form_class = ImportForm
|
||||||
export_form_class = ExportForm
|
export_form_class = ExportForm
|
||||||
export_form_class = SelectableFieldsExportForm
|
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)
|
@admin.register(Bylaws, Service, SocialAccount, Statutes, Translation)
|
||||||
class AdminClass(ImportExportMixin, ModelAdmin):
|
class AdminClass(ImportExportMixin, ModelAdmin):
|
||||||
|
|
|
@ -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",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -139,10 +139,18 @@ class User(AbstractUser):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
accepted_statutes = models.ForeignKey(
|
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(
|
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)
|
# accepted_terms = models.ManyToManyField(TermsAndConditions)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue