from django.contrib import admin
from . import models
- admin注册自定义User表:密文操作密码
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
class UserAdmin(AuthUserAdmin):
add_fieldsets = (
(None, {
'classes': ('wide',),
- 添加用户界面可操作的字段
'fields': ('username', 'password1', 'password2', 'tel', 'email', 'is_staff', 'is_active'),
}),
)
- 添加每条数据的显示的字段
list_display = ('username', 'tel', 'email', 'is_staff', 'is_active')
- 明文操作密码,admin可视化添加的用户密码都是明文,登录时用的是密文,所以用户无法登录
admin.site.register(models.User, UserAdmin)