[英]How to show validation error as the django admin default errors
Is there any way to show validation error in a standard way as the other errors ? 有什么方法可以像其他错误一样以标准方式显示验证错误?
class Student(models.Model):
...
def save(self, *args, **kwargs):
try:
super(Student, self).save(*args, **kwargs)
except ValidationError:
raise forms.ValidationError('There aren't places anymore')
from django.core.exceptions import ValidationError
class MyModel(models.Model):
def is_available(self):
#do check here
return result
def clean(self):
if not self.is_available():
raise ValidationError('Item already booked for those dates')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.