Problem with validating ModelForm
- by user561640
I use ModelForm to create my form. All works fine except 1 thing - validating the unique field.
Code:
class Article(models.Model):
...
title = models.CharField(max_length=255, unique=True, error_messages={'max_length' : 'max translation',
'unique' : 'unique translation',
'required' : 'req translation',})
...
class ArticleForm(ModelForm):
...
title = forms.CharField(max_length=255, min_length=3, error_messages={'required' : 'req translation',
'min_length' : 'min translation',
'max_length' : 'max translation',
'unique' : 'unique translation',})
But when I save my form with non-unique title I don't get my custom translated error but I get default error. How to fix it, that my unique field error is displayed?