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
- [Answered ]-Django remove duplicates in queryset and access their list of foreign key
- [Answered ]-How to add default image in django rest?
- [Answered ]-Django-Fluent-Comments – NoReverseMatch at /rohit/post/new/
- [Answered ]-Is a separate Python instance started for each instance of a Django application via Apache?
Source:stackexchange.com