Quiero agregar un campo adicional a un ModelForm. Parece fácil, pero me da el siguiente error:Django: agregue un campo a un modelo
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
Este es el código:
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.')
yo no era capaz de arreglarlo. ¿Qué estoy haciendo mal?
Está utilizando Django desde el tronco (1.4), se puede añadir la traza completa (línea de error de Django: 'si no f.editable o isinstance (f, models.AutoField) or not f.name in cleaned_data') – christophe31