我想覆盖required
错误消息。对于blank
和empty
,我可以在extra_kwargs
中执行此操作,但对于required
,它不起作用:
class Meta:
extra_kwargs = {
'enticements_info': {'error_messages': {'required': 'Test.'}},
}
我该怎么办?
答案 0 :(得分:4)
您可以通过这种方式覆盖所需的error_message。
class YourSerializer(ModelSerializer):
my_default_errors = {
'required': 'This field is required',
'blank': 'This field should not blank'
}
enticements_info = serializers.CharField(required=True, error_messages=my_default_errors, min_length=10)
class Meta:
model = Your_Model
fields = ('enticements_info')