hjwp the wonderful Test-Driven Development with a Python book demonstrates overriding the default ModelForm error messages in chapter 11 :
from django import forms
from lists.models import Item
class ItemForm(forms.models.ModelForm):
class Meta:
[...]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
empty_error = "You can't have an empty list item"
self.fields['text'].error_messages['required'] = empty_error
But then proclaims (this work continues) ...
Django 1.6 has an easier way to override field error messages. I havent managed to implement it yet, but you should watch it for free and use it!
This turned out to be a surprisingly difficult topic to search for, and I hope to save time. What is its easier way?
source
share