1👍
✅
How about this?
def clean_file_name(self):
name = self.cleaned_data['file_name']
error = ''
if len(name) < 2:
error += 'File name is too short'
if FileDescription.objects.filter(file_name = name).exists():
if error:
error += ' '
error += 'File with this name already exists'
if error:
raise forms.ValidationError(error)
return name
Or did you want them as two separate bullets? If so, you’ll need to add them to the self.errors list (see Alexander’s answer) and then raise a ValidationError to make sure the form doesn’t process.
👤Tom
0👍
From my code, hope it helps.
if isinstance(self.errors.get('field_name'), forms.util.ErrorList):
self.errors['field_name'].append(_('My error'))
else:
self.errors['field_name'] = forms.util.ErrorList([_('MyError')])
- [Answer]-Turndjango class based view dispatch ValueError
- [Answer]-Invalid syntax with conditional expressions
- [Answer]-Query filter based on GenericForeignKey's fields
- [Answer]-Django : url main page
Source:stackexchange.com