本文整理汇总了Python中django.core.exceptions.ValidationError.message_dict方法的典型用法代码示例。如果您正苦于以下问题:Python ValidationError.message_dict方法的具体用法?Python ValidationError.message_dict怎么用?Python ValidationError.message_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.exceptions.ValidationError
的用法示例。
在下文中一共展示了ValidationError.message_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_unique
# 需要导入模块: from django.core.exceptions import ValidationError [as 别名]
# 或者: from django.core.exceptions.ValidationError import message_dict [as 别名]
def validate_unique(self, exclude=None):
if not self.id:
try:
Flowvisor.objects.get(name=self.name)
e = ValidationError(_("%(model_name)s with this %(field_label)s already exists.") % {"field_label": self._meta.get_field('name').verbose_name, "model_name": self._meta.verbose_name})
e.message_dict = {}
e.message_dict["name"] = e.messages
raise e
except Flowvisor.DoesNotExist:
return self.name
super(Flowvisor, self).validate_unique(exclude)
示例2: save
# 需要导入模块: from django.core.exceptions import ValidationError [as 别名]
# 或者: from django.core.exceptions.ValidationError import message_dict [as 别名]
def save(self, image, save=True):
try:
super(FieldWallet, self).save(image)
except IOError:
# Пока никакой интернационализации, только хардкор.
e = ValidationError(u"Неверный формат изображения.")
e.message_dict = { self.field.name: [u"Выберите другой файл."] }
raise e
if self.field.process_all_formats:
self.process_all_formats()
if save:
self.instance.save()
示例3: clean
# 需要导入模块: from django.core.exceptions import ValidationError [as 别名]
# 或者: from django.core.exceptions.ValidationError import message_dict [as 别名]
def clean(self):
#ToDo: non comments, how to make it better? Overload Validation Error?
if not (self.parent or self.title):
error = ValidationError("")
error.message_dict = {u"title": u"Field is required."}
raise error