[Answered ]-How to display an error message over a field

2👍

Since you are raising a ValidationError in the clean method, you are seeing the error message on the top of the page. Raise the validation error in clean_title_ru instead

def clean_title_ru(self):
    title_ru = self.cleaned_data['title_ru']
    if not title_ru:
        raise forms.ValidationError("Title ru")

    return self.cleaned_data['title_ru']

0👍

The best way is to check value in clean_title_ru, but if you want to check multiple value you can do it what way:

def clean(self):
    cleaned_data = super(forms.ModelForm, self).clean()
    title_ru = cleaned_data['title_ru']
    if not title_ru:
        msg = u"error in Title ru"
        self._errors["title_ru"] = self.error_class([msg])

        # These fields are no longer valid. Remove them from the cleaned data.
        del cleaned_data["title_ru"]

    return self.cleaned_data

Leave a comment