显示用于将密码添加到自定义用户模型的字段-Django
我有一个自定义用户模型。我希望管理员从管理面板创建新帐户。注册课无济于事。
admin.site.register(CustomUser)
*这具有避免使用密码重复输入密码的可能性
,因此我尝试了此解决方案:
from django.contrib.auth.admin import UserAdmin
admin.site.register(CustomUser, UserAdmin)
*在上述选项中,我可以选择两次输入密码(我创建用户),但是我的自定义中的其他字段用户模型正在消失。
class CustomUser(AbstractUser):
name = models.CharField(max_length=50, blank=True, null=True)
surname = models.CharField(max_length=50, blank=True, null=True)
account_type = models.ForeignKey(Locationd, on_delete=models.CASCADE, blank=True, null=True
如何在管理面板中添加创建帐户的功能,提供可以发送给新用户并从Custome用户类中编辑所有字段的密码。
)
I have a custom user model. I want the admin to create new accounts from the admin panel. Registering a class doesn't help.
admin.site.register(CustomUser)
*This has the effect of avoiding the possibility of double-entering the password
So I try this solution:
from django.contrib.auth.admin import UserAdmin
admin.site.register(CustomUser, UserAdmin)
*In the above option, I have the option to enter the password twice (whean i create user), but the other fields from my custom user model are disappearing.
class CustomUser(AbstractUser):
name = models.CharField(max_length=50, blank=True, null=True)
surname = models.CharField(max_length=50, blank=True, null=True)
account_type = models.ForeignKey(Locationd, on_delete=models.CASCADE, blank=True, null=True
How to add the ability to create accounts in the admin panel, giving a password that can be sent to the new user and editing all fields from the custome user class.
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从旧项目中使用自己的django表格
此代码,因此将字段名称更改为您想要的任何内容
You can use your own Django form
This code from an old project so change the fields names to whatever you want
您需要取消注册
用户
模型,然后添加自定义用户You need to unregister the
user
model then add your custom user