dimanche 28 juin 2015

Customize UserAdmin multiple times

I'd like to display custom models in the user admin backend from multiple apps. I can do that for just one app with the classical admin.py commands :

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from my_user_profile_app.models import Employee

class EmployeeInline(admin.StackedInline):
    model = Employee
    can_delete = False
    verbose_name_plural = 'employee'

# Define a new User admin
class UserAdmin(UserAdmin):
    inlines = (EmployeeInline, )

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

However, the following app replaces all the previous registered models with its own, and so on… Is there a clean way to append models in the user admin backend ? It's like the app's admin.py must be aware of all previous customizations made, and register them all again.

Aucun commentaire:

Enregistrer un commentaire