Customizing an Admin form in Django while also using autodiscover

后端 未结 2 1056

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)
    
    0 讨论(0)
  • 2020-12-07 18:40

    I think it might be easier to do this with a custom auth backend and thus remove the need for a customized ModelAdmin.

    I did something similar with this snippet: http://www.djangosnippets.org/snippets/74/

    0 讨论(0)
提交回复
热议问题