I have created a Django form:
class AddFaceForm(forms.ModelForm):
class Meta:
model = Face
fields = ('person', 'x', 'y', 'w', 'h')
In the Face model, w is defined as
w = models.DecimalField(
'Relative width',
validators=[MinValueValidator(0.05), MaxValueValidator(1)]
)
If a user enters 0 for the width, the error message Django returns upon form validation is
Ensure this value is greater than or equal to 0.05.
So it nicely contains the value from the MinValueValidator. I would like to change it to "Relative width must be >= 0.05".
To achieve it, I tried customising errors in AddFaceForm Meta
class AddFaceForm(forms.ModelForm):
class Meta:
model = Face
fields = ('person', 'x', 'y', 'w', 'h')
error_messages = {
'w': {
'min_value': 'Relative width must be >= 0.05'
}
}
But this means hard-coding the 0.05 value. I would like to read it from the model definition. How can this be done?