Using Django auth UserAdmin for a custom user model

前端 未结 6 1188
甜味超标
甜味超标 2020-11-30 17:48

From the Django.Contrib.Auth docs:

Extending Django’s default User If you’re entirely happy with Django’s User model and you just w

6条回答
  •  被撕碎了的回忆
    2020-11-30 18:01

    cesc's answer wasn't working for me when I attempted to add a custom field to the creation form. Perhaps it's changed since 1.6.2? Either way, I found adding the field to both fieldsets and add_fieldsets did the trick.

    ADDITIONAL_USER_FIELDS = (
        (None, {'fields': ('some_additional_field',)}),
    )
    
    class MyUserAdmin(UserAdmin):
        model = MyUser
    
        add_fieldsets = UserAdmin.add_fieldsets + ADDITIONAL_USER_FIELDS
        fieldsets = UserAdmin.fieldsets + ADDITIONAL_USER_FIELDS
    
    admin.site.register(MyUser, MyUserAdmin)
    

提交回复
热议问题