Overriding the default error message for a ModelForm

Posted by Jude Osborn on Stack Overflow See other posts from Stack Overflow or by Jude Osborn
Published on 2010-05-29T18:12:31Z Indexed on 2010/05/29 18:22 UTC
Read the original article Hit count: 219

Filed under:

Is there any way to override a error_message text for all the fields of a ModelForm's, without having to include all the field info in the ModelForm?

For example, let's say I have a (very simple) model like this:

People(models.Model):
     name = models.CharField(max_length=128, null=True, blank=True, help_text="Please type your name.")
     age = models.IntegerField(help_text="Please type your age.")

I don't like the cut and dry default messages, such as, "Enter a whole number.", so I'd like to change them to something a bit nicer like "Please type a number." Ideally I'd be able to add an "error_message" property in the model, but the model does not support that property. So does that mean I have to basically duplicate all the model info in my ModelForm, or is there a way around that?

© Stack Overflow or respective owner

Related posts about django-forms