Monday, January 3, 2011

Problem with validating ModelForm

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?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment