Django AbstractUser管理后台密码明文解决
程序员文章站
2022-03-25 22:01:26
解决方案 models.py admin.py ......
解决方案
models.py
class user(abstractuser): roles = models.manytomanyfield("role")
admin.py
from django.contrib.auth.admin import useradmin #使用django自己的useradmin来注册 from django.utils.translation import gettext, gettext_lazy as _ from .models import user class useradmin(useradmin): #重写fieldsets在admin后台加入自己新增的字段 fieldsets = ( (none, {'fields': ('username', 'password')}), (_('personal info'), {'fields': ('first_name', 'last_name', 'email')}), (_('permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}), (_('important dates'), {'fields': ('last_login', 'date_joined')}), (_('roles'), {'fields': ('roles',)}), ) admin.site.register(user, useradmin)