Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在管理员界面中显示自定义错误_Python_Django_Django Models_Django Admin - Fatal编程技术网

Python 如何在管理员界面中显示自定义错误

Python 如何在管理员界面中显示自定义错误,python,django,django-models,django-admin,Python,Django,Django Models,Django Admin,我在pre_save中引发了一个validationError,但是每当我尝试创建一个新对象时,我都会看到一个带有错误的黄页,而不是像其他对象一样出现红色错误 @receiver(pre_save, sender=Student) def student_pre_save(sender,instance, **kwargs): if instance.classroom.student_set.count() == instance.classroom.QttMax_Stu:

我在pre_save中引发了一个validationError,但是每当我尝试创建一个新对象时,我都会看到一个带有错误的黄页,而不是像其他对象一样出现红色错误

@receiver(pre_save, sender=Student)
def student_pre_save(sender,instance, **kwargs):

    if instance.classroom.student_set.count() == instance.classroom.QttMax_Stu:
        raise ValidationError("No places left")
我把这个放在模型里,效果很好

def clean(self, *args, **kwargs):
    try:
        super(Student, self).save(*args, **kwargs)
    except ValidationError:
        raise ValidationError("No places left")