2024-04-26 12:47:21 发布
网友
是否有任何方法可以将验证错误作为其他错误以标准方式显示?在
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')
相关问题 更多 >
编程相关推荐