【发布时间】:2014-06-11 00:22:37
【问题描述】:
抱歉,如果我忽略了 Carl Meyer 的 django-forms-utils 文档中的某些内容。我们将它用于在 django 的非管理页面中获取字段集。这是我在 forms.py 中的代码:
class MentorApplicationForm(ApplicationForm):
email = forms.EmailField(label='Email', error_messages={'email_exists': 'This email id has already been used. Please use a different email id to submit a new application. Or write to applications@mentortogether.org for clarifications.'},)
dob = forms.DateField(label=u'Date of Birth',
help_text=u'Format dd/mm/yyyy',
required=True,
input_formats=("%d/%m/%Y",))
class Meta:
model = MentorApplication
fieldsets = [('Personal Information', {'fields': ['email','dob'],})]
我想要的是这样的:
class MentorApplicationForm(ApplicationForm):
email = forms.EmailField(label='Email', error_messages={'email_exists': 'This email id has already been used. Please use a different email id to submit a new application. Or write to applications@mentortogether.org for clarifications.'},)
dob = forms.DateField(label=u'Date of Birth',
help_text=u'Format dd/mm/yyyy',
required=True,
input_formats=("%d/%m/%Y",))
class Meta:
model = MentorApplication
fieldsets = [('Personal Information', {'fields': ['first_name', 'last_name', 'email','dob',],})]
我在 MentorApplication 模型中定义了“first_name”和“last_name”,我不想在 forms.py 中重新定义它们。这是the doc,它说它是从ModelForm 扩展而来的,这就是我期望它从MentorApplication 模型(在Meta 中提到)中获取字段的地方。有人可以帮我找出原因并建议我一个解决方法(我对重新定义它的形式非常抗拒,因为我不得不重复自己)。提前致谢。
【问题讨论】:
标签: django django-forms