【发布时间】:2012-04-19 11:19:37
【问题描述】:
我有一个UserAdmin,我像这样定义了一个UserProfileInline:
from ...
from django.contrib.auth.admin import UserAdmin as UserAdmin_
class UserProfileInLine(admin.StackedInline):
model = UserProfile
max_num = 1
can_delete = False
verbose_name = 'Profile'
verbose_name_plural = 'Profile'
class UserAdmin(UserAdmin_):
inlines = [UserProfileInLine]
我的UserProfile 模型有一些必填字段。
我想要的是强制用户不仅输入用户名和重复密码,而且至少输入必填字段,以便创建 UserProfile 实例并将其关联到正在添加的 User .
如果我在创建用户时在UserProfileInline 的任何字段中输入任何内容,它会毫无问题地验证表单,但如果我不触摸任何字段,它只会创建用户并且UserProfile 不会发生任何事情。
有什么想法吗?
【问题讨论】:
标签: django django-admin