django - Argument of type 'NoneType' is not iterable when trying to update a model object -
getting error argument of type 'nonetype' not iterable
, can't figure out why.
it happens @ line if model_form.is_valid():
views.py
def update_model(request, pricemodel_id): """ update part given id. """ pricemod = part.objects.get(id=pricemodel_id) if request.method == "post": print "post request" model_form = priceform(request.post, request.files, instance=pricemod) model_form.is_update = true if request.user == pricemod.adder: #from ipdb import set_trace; set_trace() if model_form.is_valid():
forms.py
class priceform(modelform): # price form: form associated part model def __init__(self, *args, **kwargs): super(priceform, self).__init__(*args,**kwargs) self.is_update=false choices = unipart.objects.all().values('manufacturer').distinct() def clean(self): if self.cleaned_data , 'modelname' not in self.cleaned_data: raise forms.validationerror("some error message") if not self.is_update: return self.cleaned_data return self.cleaned_data class meta: model = part
looks because wrong indention in clean method. current doesn't return anything, i.e returns none
, must return self.cleaned_data
. of clean
method code under if
, raise exception. , if if
not matched, none returned.
try this:
class priceform(modelform): # ... def clean(self): if self.cleaned_data , 'modelname' not in self.cleaned_data: raise forms.validationerror("some error message") if not self.is_update: return self.cleaned_data return self.cleaned_data # ...
Comments
Post a Comment