I created a model form which has custom clean()
method. But this clean()
method is not working anymore since I created a formset out of that modelform as it is unable to find the data in the QueryDict
. So what to do now to make it work(find the data related to that form in the formset QueryDict)?
This is the member form:
class option_form(ModelForm):
class Meta:
model = option
exclude = ('warval','user')
def clean_value(self):
self.data = self.data.copy()
print(self.data)
if self.data['value']=='lol@lol.co':
raise forms.ValidationError("This can't be your email address")
return self.data['value']
And this is the error:
Exception Type: MultiValueDictKeyError
Exception Value: "Key 'value' not found in <QueryDict: {u'form-1-value': [u''], u'form-INITIAL_FORMS': [u'1'], u'form-TOTAL_FORMS': [u'2'], u'form-MAX_NUM_FORMS': [u''], u'form-0-id': [u'1'], u'form-1-id': [u''], u'csrfmiddlewaretoken': [u'e645de635fe47559ac540eb32ea4d08d'], u'form-0-value': [u'lol@lol.co']}>"