[Answered ]-Overriding clean(), data not accessible

1👍

You need to return self.cleaned_data from both the base and the subclass methods.

1👍

I believe returning the self.cleaned_data to the base class only should work.

class MyForm(forms.Form):
    field = forms.CharField()

    def clean(self):
        "do stuff"
        return self.cleaned_data

    class MyEmailingForm(MyForm):
        def clean(self):
            super(MyEmailingForm, self).clean()
            send_mail('Form data',
              self.cleaned_data['field'],
              'Form <noreply@myform.co.uk>',
              ["formdata@myform.co.uk"],
              fail_silently=True)
              return self.cleaned_data
👤vibhor

0👍

You have to use the is_valid() method first.

https://docs.djangoproject.com/en/dev/topics/forms/

0👍

Actually the field self.cleaned_data['field'] you are setting in base is not included in cleaned_data.

try

class MyForm(forms.Form):
    field = forms.CharField()

    def clean(self):
        cd = self.cleaned_data
        "do stuff with cd"
        return cd
👤Ahsan

Leave a comment