Problem with validating ModelForm

Posted by user561640 on Stack Overflow See other posts from Stack Overflow or by user561640
Published on 2011-01-03T19:05:52Z Indexed on 2011/01/04 1:54 UTC
Read the original article Hit count: 172

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about django