2014-04-25 72 views
0

對不起,如果我在Carl Meyer的django-forms-utils文檔中忽略了某些內容。我們使用它在django中的非管理頁面中獲取字段集。這是我在forms.py代碼:使用django-form-utils字段集中的模型字段

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 [email protected] 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 [email protected] 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」和「姓氏」我不要」我想在forms.py中重新定義它們。這裏是the doc它說它從ModelForm擴展,這就是我期望從MentorApplication模型(在Meta中提到)中獲取字段的地方。有人可以幫我找出原因,並且建議我採取一種解決方法(我對形式進行重新定義非常有抵抗力,因爲我必須重複自己)。提前致謝。

回答

0

我正在從BetterForm擴展ApplicationForm(MentorApplicationForm的超級)。我應該從'BetterModelForm'擴展它。