Django.core.validators 从 shell 中忽略了 MinMaxValueValidator

Django.core.validators MinMaxValueValidator ignored from shell

我正在使用创建的 django 1.10

from django.core.validators import MinValueValidator
from django.core.validators import MaxValueValidator

class B(models.Model):
    address = models.PositiveSmallIntegerField(validators=[MinValueValidator(0), MaxValueValidator(63)], blank=True, null=True)

当我进入 shell_plus 并执行以下操作时:

x=B()
x.address='1973'
x.save()

该行已被记录。 Triyng 与管理 Web 界面相同,表单给出错误,为什么 shell 允许保存记录?

这是正确的。

来自docs for How validators are run

...Note that validators will not be run automatically when you save a model, but if you are using a ModelForm, it will run your validators on any fields that are included in your form....