Django 管理用户创建表单中未显示额外字段
Extra field is not showing in Django administration user creation form
我写了 forms.py 和 admin.py。但是 Django 管理用户创建表单中没有显示电子邮件、全名等额外字段。
我检查了我的一个项目,我就是这样做的。
class UserAdmin(BaseUserAdmin):
fieldsets = (
(None, {'fields': ('cpf', 'password')}),
('Personal Info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': ('is_active', 'is_superuser', 'is_admin', 'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
limited_fieldsets = (
(None, {'fields': ('cpf',)}),
('Personal info', {'fields': ('first_name', 'last_name')}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('cpf', 'password1', 'password2')
}),
)
form = UserChangeForm
add_form = UserCreationForm
change_password_form = auth_admin.AdminPasswordChangeForm
list_display = ('cpf', 'first_name', 'last_name', 'is_admin')
list_filter = ('is_active', 'is_admin')
search_fields = ('first_name', 'last_name', 'cpf')
ordering = ('cpf',)
readonly_fields = ('last_login',)
filter_horizontal = ('groups', 'user_permissions')
我检查了我的一个项目,我就是这样做的。
class UserAdmin(BaseUserAdmin):
fieldsets = (
(None, {'fields': ('cpf', 'password')}),
('Personal Info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': ('is_active', 'is_superuser', 'is_admin', 'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
limited_fieldsets = (
(None, {'fields': ('cpf',)}),
('Personal info', {'fields': ('first_name', 'last_name')}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('cpf', 'password1', 'password2')
}),
)
form = UserChangeForm
add_form = UserCreationForm
change_password_form = auth_admin.AdminPasswordChangeForm
list_display = ('cpf', 'first_name', 'last_name', 'is_admin')
list_filter = ('is_active', 'is_admin')
search_fields = ('first_name', 'last_name', 'cpf')
ordering = ('cpf',)
readonly_fields = ('last_login',)
filter_horizontal = ('groups', 'user_permissions')