我创建了一个带有字段选择的学生模型。但是,当我保存它时,它不会验证选项是否在我在模型字段中指定的选项中。
为什么它不阻止我使用我在模型中未指定的选项保存新对象?
这是模型:
class Student(models.Model):
year_in_school = models.CharField(
max_length=4,
choices= [
('FRES', 'Freshman'),
('SOPH', 'Sophomore'),
],
)
这是我在 shell 中编写的代码:
>>> from app.models import Student
>>> new_student = Student.objects.create(year_in_school='HACK')
>>> new_student.year_in_school
'HA'