I understand the form of the document http://docs.djangoproject.com/en/dev/ref/models/fields/ that you can add error_messages to the model field and provide your own error messages. However, what are the dictation keys that you must pass?
class MyModel(models.Model): some_field = models.CharField(max_length=55, error_messages={'required': "My custom error"})
If it is easier to do on the model used model, which will also work. I would prefer not to create an explicit creation of each field and their type again. This is what I tried to avoid:
class MyModelForm(forms.ModelForm): some_field = forms.CharField(error_messages={'required' : 'Required error'})
Update 2: Test code used in my project
My model:
class MyTestModel(models.Model): name = models.CharField(max_length=127,error_messages={'blank' : 'BLANK','required' : 'REQUIRED'})
My form:
class EditTestModel(ModelForm): class Meta: model = MyTestModel
My view:
tf = EditTestModel({'name' : ''}) print tf.is_valid() # prints False print tf.full_clean() # prints None print tf # prints the form, with a <li> error list containg the error "This field is required" <tr><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_name" type="text" name="name" maxlength="127" /></td></tr>
source share