开发者

ValidationError giving me exception

My admin:

from django.core.exceptions import ValidationError
def save_model(self, request, obj, form, change):
        if obj.foo == True and obj.bar == '':
            raise ValidationError('Please enter the password.')

My model is:

  foo = models.BooleanField(default=False)
  bar = models.CharField(max_length=50, null=True, blank=True)

I want to validate the models that when foo is True the bar can't be null. But It is giving me the 500. Exception Value: [u'Please enter the password.']开发者_如何学JAVA


You're supposed to do your validation in the ModelForm, not the ModelAdmin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜