Customizing an Admin form in Django while also using autodiscover

后端 未结 2 1074

I want to modify a few tiny details of Django\'s built-in django.contrib.auth module. Specifically, I want a different form that makes username an email field

2条回答
  •  半阙折子戏
    2020-12-07 18:22

    None of the above. Just use admin.site.unregister(). Here's how I recently added filtering Users on is_active in the admin (n.b. is_active filtering is now on the User model by default in Django core; still works here as an example), all DRY as can be:

    from django.contrib import admin
    from django.contrib.auth.admin import UserAdmin
    from django.contrib.auth.models import User
    
    class MyUserAdmin(UserAdmin):
        list_filter = UserAdmin.list_filter + ('is_active',)
    
    admin.site.unregister(User)
    admin.site.register(User, MyUserAdmin)
    

提交回复
热议问题