在 Django Admin 中创建用户时,它不会散列密码吗?

When creating a user in Django Admin it does not hash the password?

我正在尝试使用 Django REST 框架从我的 Django Admin(该项目是一个休息 API)创建一个用户。

admin.py

class UserFrame(UserAdmin):
    list_display = ["name", "email", "date_of_creation", "is_active"]
    list_editable = ["is_active"]
    
admin.site.register(models.AccountProfile, UserFrame) 

我得到的错误: 为 AccountProfile

指定的未知字段 (date_joined、last_name、first_name)

AccountProfile 是我的自定义用户模型,它继承自 AbstractBaseUser 并有一个 BaseUserManager。

您创建 UserFrame 模型的方式似乎没有使用您经理的 create_user 方法。

如果您创建自定义用户,您需要定义一个自定义模型表单和模型管理员来正确处理密码。除非在 Django 管理中创建用户时不会对密码进行哈希处理。

在这里查看 https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#a-full-example 此示例可帮助您创建自定义用户。

user.set_password(raw_password)

这是您需要包含在自定义管理器中的方法。 让它知道它必须散列这些密码。