How can I overwrite the default form error messages (for example: need them in other language) for the all apps in my project (or at least for 1 app)
Thanks!
Hmm, seems there is no easy workaround for the problem.
Wile skimming through the django code, I've found that default error messages are hard-coded into each form field class, for ex:
class CharField(Field):
default_error_messages = {
'max_length': _(u'Ensure this value has at most %(max)d characters (it has %(length)d).'),
'min_length': _(u'Ensure this value has at least %(min)d characters (it has %(length)d).'),
}
And the easiest way is to use the error_messages argument, so I had to write the wrapper function:
def DZForm(name, args = {}):
error_messages = {
'required': u'required',
'invalid': u'invalid',
}
if 'error_messages' in args.keys():
args['error_messages'] = error_messages.update(args['error_messages'])
else:
args['error_messages'] = error_messages
return getattr(forms, name)(**args)
If smdb knows more elegent way of doing this would really appreaciate to see it :)
Thanks!