在django表单utils字段集中使用模型中的字段

在django表单utils字段集中使用模型中的字段,django,django-forms,Django,Django Forms,很抱歉,如果我在卡尔·迈耶的django forms utils文档中忽略了一些内容。我们在django的非管理员页面中使用它来获取字段集。以下是我在forms.py中的代码: class MentorApplicationForm(ApplicationForm): email = forms.EmailField(label='Email', error_messages={'email_exists': 'This email id has already been use

很抱歉,如果我在卡尔·迈耶的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',],})]

我已经在应用程序模型中定义了“first_name”和“last_name”,我不想在forms.py中重新定义它们。这里是它从ModelForm扩展而来的地方,这也是我希望它从应用程序模型(Meta中提到)中获取字段的地方。有人能帮我找出原因并给我建议一个解决办法吗(我很不愿意在形式上重新定义它,因为我必须重复我自己)。提前感谢。

我从BetterPerform扩展了ApplicationForm(导师应用程序表单的超级)。我应该从“BetterModelForm”扩展它