开发者

Overriding the default error message for a ModelForm

Is there any way to override a error_message text for all the fields o开发者_如何学JAVAf 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?


You can try to use this example to create functions for validation based on django native functions and your error messages )) .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜