python - Django创建用户配置文件
问题描述
我为我的系统创建了一个用户配置文件模型。我创建了所有模型,并且效果很好。我有一个表格,表格也有效。但是当我从管理页面查看用户创建表单时,它看起来不一样。
有一些缺失的部分,如等级,comp_name
。我该如何解决?
模型.py
class UserProfile(models.Model):
ranks = (
('xxx', 'xxx'),
...
)
comp_name = models.CharField(max_length=200, default="Choose")
user_id = models.UUIDField(default=uuid.uuid4(), editable=False, unique=True)
username = models.CharField(max_length=500)
first_name = models.CharField(max_length=200, default=None)
last_name = models.CharField(max_length=200, default=None)
password = models.CharField(max_length=50)
email = models.EmailField(max_length=254)
rank = models.CharField(max_length=200, choices=ranks)
表格.py
class SignUpForm(UserCreationForm):
comp_name = forms.CharField(label='What is your company name?')
email = forms.CharField(max_length=254)
rank = forms.ChoiceField(label='What is your rank?', choices=UserProfile.ranks)
first_name = forms.CharField(max_length=250)
last_name = forms.CharField(max_length=250)
comp_name = forms.ModelChoiceField(queryset=CompanyProfile.objects.all())
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'comp_name', 'password1', 'password2', 'rank'
admin 管理面板“更改用户”屏幕
解决方案
在forms.py
class SignUpForm(UserCreationForm):
comp_name = forms.CharField(label='What is your company name?')
email = forms.CharField(max_length=254)
rank = forms.ChoiceField(label='What is your rank?', choices=UserProfile.ranks)
first_name = forms.CharField(max_length=250)
last_name = forms.CharField(max_length=250)
comp_name = forms.ModelChoiceField(queryset=CompanyProfile.objects.all())
class Meta:
model = User --> change to UserProfile
fields = ('username', 'first_name', 'last_name', 'email', 'comp_name', 'password1', 'password2', 'rank'
推荐阅读
- eclipse - Eclipse 命令行格式化非 java (IntelliJ Eclipse xhtml 格式化差异)
- powerbi - 过滤上游表以仅检索存在下游记录的记录
- python - 使用 hexbin PCA 的多组数据
- python - 如何在 plotly express 的 mapbox 上显示特定数据
- vb.net - 如何正确使用同步锁一次只允许调用一个函数
- python-3.x - 如果具有索引值的熊猫数据框中存在句子,则尝试返回该行
- python - 尝试使用 asyncio sqlalchemy 它只是冻结
- c# - 从前端接收 GMT +0 日期字符串时,如何在后端将其设为 GMT +2 日期对象?
- reactjs - 反应渲染/片段/语法/意外令牌
- google-apps-script - 循环遍历谷歌工作表中的列和行以标记 gmail - 谷歌应用脚本