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
.
精彩评论