Estoy recibiendo el siguiente error al intentar enviar un formulario:argumento de tipo 'NoneType' no está Iterable con ModelForm
argument of type 'NoneType' is not iterable
Mi clase de formulario es el siguiente:
class requestform(ModelForm):
def __init__(self, *args, **kwargs):
super(requestform, self).__init__(*args,**kwargs)
self.is_update=False
requestedpart = forms.CharField (label="Requested Part", max_length=80, required= True)
librarytype = forms.TypedChoiceField (label="Type", choices = ((1, "Type1"), (2, "Type2"), (3, "Type3")), coerce = lambda x: bool(int(x)), widget = forms.RadioSelect, required= True)
requestformat = forms.TypedChoiceField (label="Format", choices = ((1, "Format1"), (2, "Format2")), coerce = lambda x: bool(int(x)), widget = forms.RadioSelect, required= True)
def clean(self):
if 'requestedpart' not in self.cleaned_data:
return
if not self.is_update:
return self.cleaned_data
class Meta:
model = LibraryRequest
mi punto de vista es el siguiente
if request.method == "POST":
formtoaddrequest = requestform(request.POST, request.FILES)
if requestform.is_valid(formtoaddrequest):
new_request = formtoaddrequest.save(commit=False)
new_request.requestadder = request.user
new_request.save()
request.user.message_set.create(message=_("You have saved '%(requestedpart)s'") % {'requestedpart': new_request.requestedpart})
Aquí está mi rastreo
Traceback:
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/AB/Desktop/store/project/views.py" in view_requests
201. if formtoaddmodel.is_valid():
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
121. return self.is_bound and not bool(self.errors)
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in _get_errors
112. self.full_clean()
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
269. self._post_clean()
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/models.py" in _post_clean
316. self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
File "/Users/AB/Desktop/myenv2/lib/python2.7/site-packages/django/forms/models.py" in construct_instance
40. or not f.name in cleaned_data:
Exception Type: TypeError at /project/view_requests/
Exception Value: argument of type 'NoneType' is not iterable
¿Alguna idea de por qué podría obtener este error?
post ypur traceback –
'requestform.is_valid (formtoaddrequest)' es un uso no válido ... Debe ser 'formtoaddquest.is_valid()' [Doc está aquí] (https://docs.djangoproject.com/en/ 1.4/ref/forms/api/# django.forms.Form.is_valid) – FallenAngel
Gracias !!!!! Estaba experimentando con diferentes tipos de formularios y debo haber cambiado esa línea en el camino. – user1328021