如何ValidationException在 django 的模型clean方法中提高字段绑定?
from django.core.exceptions import ValidationError
def clean(self):
if self.title:
raise ValidationError({'title': 'not ok'})
以上没有将错误添加到title字段(使用表单时),而是添加到非字段错误(__all__)。
我知道如何在表单 ( self._errors['title'] = self.error_class([msg])) 中执行此操作,但在模型方法self._errors中不存在。clean