3👍
✅
Looks like it is because wrong indention in your clean method. Current it doesn’t return anything, i.e it returns None
, but must return the self.cleaned_data
. All of your clean
method code is under if
, which will raise an exception. And if this if
is not matched, None is returned.
Try this:
class priceform(ModelForm):
# ...
def clean(self):
if self.cleaned_data and '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
# ...
Source:stackexchange.com