7
ModelForm에 추가 필드를 추가하고 싶습니다. 그것은 쉽게 보이지만, 나는 다음과 같은 오류 얻을 :Django : modelform에 필드 추가
class NodeForm(forms.ModelForm):
password2 = forms.CharField(max_length=20, required=True, widget=forms.PasswordInput())
class Meta:
model = Node
def __init__(self, *args, **kwargs):
super(NodeForm, self).__init__(*args, **kwargs)
# css classes for fields
for v in self.fields:
self.fields[v].widget.attrs['class'] = 'text ui-widget-content ui-corner-all'
def clean(self):
''' Calls parent clean() and performs additional validation for the password field '''
super(NodeForm, self).clean()
password = self.cleaned_data.get('password')
password2 = self.cleaned_data.get('password2')
# password and password2 must be the same
if password != password2:
raise forms.ValidationError('I due campi password non corrispondono.')
내가 그것을 고칠 수 없습니다 :
Django Version: 1.4 pre-alpha SVN-16573
Exception Type: TypeError
Exception Value:
argument of type 'NoneType' is not iterable
Exception Location: /usr/local/lib/django-trunk/django/forms/models.py in construct_instance, line 39
Python Executable: /usr/bin/python
Python Version: 2.6.6
이 코드입니다. 내가 도대체 뭘 잘못하고있는 겁니까?
당신이 here 설명 된대로clean
방법에서 데이터를 청소 반환해야
당신은 트렁크 (1.4)에서 장고를 사용하고, 당신은 장고에 전체 스택 트레이스 (오류 라인을 추가 할 수 있습니다 :'경우 f.editable 또는 isinstance (f, models.AutoField)가 아니거나 f.name in cleaned_data'가 아닙니다.) – christophe31