Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

如何在Django amin中添加电子邮件添加用户页面

我创建了一个CustomUser(AbstractUser)模型,在这个模型中我想在admin添加用户页面中添加电子邮件ID字段。当前默认情况下,首先我们可以输入用户名和密码,创建用户名和密码后,我们将重定向到另一个页面字段可用我希望添加用户页面上的此电子邮件字段可行吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

admin.py您的应用程序中,创建一个,ModelAdmin然后使用fields属性在视图中包括电子邮件字段。

例:

from django.contrib import admin
from myproject.myapp.models import CustomUser

class CustomUserAdmin(admin.ModelAdmin):
    fields = ('username', 'password', 'email')

admin.site.register(CustomUser,CustomUserAdmin)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...