当前位置: 动力学知识库 > 问答 > 编程问答 >

python - django 1.3 setting custom error_messages on models.IntegerField seems not to work

问题描述:

Doing some maintenance on a django 1.3 app.

There is a class Application with (amonst others) an IntegerField:

area = models.IntegerField()

They are wanting a different error message for invalid entries.

After sifting through all the docs and trying many approaches I haven't managed to resolve this.

For example I tried:

area = models.IntegerField(error_messages={'invalid': 'Custom message'})

Also:

class ApplicationForm(ModelForm):

area = forms.IntegerField({'invalid': 'Custom message'})

class Meta:

model = Application

fields = ('...) #all the other fields go here

Also other approaches didn't work. I always get the standard "Enter a whole number." error message.

分享给朋友:
您可能感兴趣的文章:
随机阅读: