django-allauth-ens/example/app/admin.py

28 lines
770 B
Python
Raw Normal View History

2017-08-03 12:41:30 +02:00
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import AbstractUser
from django.utils.translation import ugettext as _
from .models import User
class ExtendedUserAdmin(UserAdmin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
base_fields = [field.name for field in AbstractUser._meta.fields]
all_fields = [field.name for field in self.model._meta.fields]
extra_fields = [
f for f in all_fields
if f not in base_fields and f != self.model._meta.pk.name
]
self.fieldsets += (
(_('Champs additionnels'), {'fields': extra_fields}),
)
admin.site.register(User, ExtendedUserAdmin)