我在django 1.6中使用过代码但是在django 1.8.6中尝试时我得到了:
AttributeError: 'SignupDataForm' object has no attribute 'fields'
在这一行,但每当要求领域时也是如此:
merged_field_order = list(self.fields.keys())
我的SignupDataForm是一个声明如下的子项:
class SignupDataForm(BaseUserDataForm):
reg_user_badge = forms.CharField(label="Give Points to a Friend",required=False,widget = TextInput(attrs={'placeholder': 'Username (optional)'}),validators=[validate_friendname])
class Meta(BaseUserDataForm.Meta):
model = UserData
fields = BaseUserDataForm.Meta.fields + ('terms_conditions',)
#terms_conditions is also a model field but not added to the parent definition
def __init__(self, *args, **kwargs):
super(SignupDataForm, self).__init__(*args, **kwargs)
self.fields['terms_conditions'].required = False
self.fields['gender'].widget = Select(choices=GENDER_CHOICES,attrs={'class':'signup_select',})
self.fields['password2'].widget.attrs['onblur'] ="check_pass()"
self.fields['password1'].widget.attrs['onblur'] ="check_pass()"
def clean(self):
#clean overwrite
奇怪的是,如果我使用父表单,一切正常,我没有错误。此外,如果我在META声明中放置一个打印字段,那么带有字段的元组就在那里。父母的短代码在这里:
class BaseUserDataForm(forms.ModelForm):
url = forms.CharField(max_length = 30, label="Don't type here (anti spam protection)",validators=[validate_name_honeypots])
class Meta:
model = UserData
fields = ('****model fields named without terms_conditions field****')
def __init__(self, *args, **kwargs):
super(BaseUserDataForm, self).__init__(*args, **kwargs)
错误发生在另一个孩子身上:
class BaseSignupForm(SignupDataForm):
username = forms.CharField(label=_("Username"),
max_length=get_username_max_length(),
min_length=app_settings.USERNAME_MIN_LENGTH,
widget=forms.TextInput(
attrs={'placeholder':
_('Username'),
'autofocus': 'autofocus'}))
email = forms.EmailField(widget=forms.TextInput(
attrs={'type': 'email',
'placeholder': _('E-mail address')}))
def __init__(self, *args, **kwargs):
email_required = kwargs.pop('email_required',
app_settings.EMAIL_REQUIRED)
self.username_required = kwargs.pop('username_required',
app_settings.USERNAME_REQUIRED)
super(BaseSignupForm, self).__init__(*args, **kwargs)
# field order may contain additional fields from our base class,
# so take proper care when reordering...
field_order = ['email', 'username']
merged_field_order = list(self.fields.keys())
有人知道我做错了什么吗?
更新 - 解决: 解决了。根本不是python ModelForm或allauth问题。下面有一个表格,部分包装和部分评论,我没有看到,它引起了一个意图错误,表明它是如此奇怪的方式......