[Answered ]-Raising ValidationError when it comes to custom validation

2๐Ÿ‘

โœ…

I think your problem for your second approach is that you didnโ€™t captured the cleaned_data that is returned from parent clean method. Also you were calling the wrong super method. super should be called on the form class itself, not the class that current class is inherited from. I think you should:

class CurrentForm(forms.Form):

    def clean(self):
        cleaned_data = super(CurrentForm, self).clean()
        if 'departure_date_time_plain' in cleaned_data and 'arrival_date_time_plain' not in cleaned_data:
            self._errors['arrival_date_time_plain'] = [u'PUT HERE SOME DATE']

        if 'departure_date_time_plain' not in cleaned_data and 'arrival_date_time_plain' in cleaned_data:
            self._errors['arrival_date_time_plain'] = [u'PUT HERE SOME DATE']
        return self.cleaned_data

You will always have the best tutorial by checking out django docs.

๐Ÿ‘คShang Wang

Leave a comment