django中的自定义用户模式不允许在admin中设置密码 [英] Custom user model in django does not allow setting password in admin

查看:663
本文介绍了django中的自定义用户模式不允许在admin中设置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



问题是在管理员中,在用户编辑屏幕上,我得到显示当前密码哈希,而不是设置密码非常有用的界面。



我在Python 2.7中使用Django 1.5b1。



为了管理用户界面,我如何说服Django管理员对待我的用户模型与管理本机用户的方式相同?

解决方案

文档建议您需要使用管理员注册自定义模型,还可以定义几种方法,以便管理界面适用于自定义用户模型。



您可能还需要为User定义内置表单。



自定义用户和django.contrib.admin



你也需要重新用管理员提供您的自定义用户模型。如果您的自定义用户模型扩展了AbstractUser,您可以使用Django的现有UserAdmin类。但是,如果您的用户模型扩展了AbstractBaseUser,则需要定义一个自定义的ModelAdmin类。


I have created a custom user model which I am successfully using within my app.

The problem is that within the Admin, on the user edit screen, I get a display of the present password hash, instead of the very useful interface for setting the password.

I am using Django 1.5b1 on Python 2.7.

How can I convince the Django admin to treat my user model the same way it treats the native User, for the sake of the admin user interface?

解决方案

Documentation suggest that you need to register the custom model with admin and also define few methods as well so that admin interface works with custom user model.

You may also have to define built-in forms for User.

From Custom users and django.contrib.admin

You will also need to register your custom User model with the admin. If your custom User model extends AbstractUser, you can use Django's existing UserAdmin class. However, if your User model extends AbstractBaseUser, you'll need to define a custom ModelAdmin class.

这篇关于django中的自定义用户模式不允许在admin中设置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆