Ana*_*tol 9 python django postgresql modelchoicefield
我创建了一个带有字段选择的学生模型。但是,当我保存它时,它不会验证该选择是否在我在模型字段中指定的选择中。
为什么它不会阻止我使用模型中未指定的选项保存新对象?
这是模型:
class Student(models.Model):
year_in_school = models.CharField(
max_length=4,
choices= [
('FRES', 'Freshman'),
('SOPH', 'Sophomore'),
],
)
Run Code Online (Sandbox Code Playgroud)
这是我在 shell 中编写的代码:
>>> from app.models import Student
>>> new_student = Student.objects.create(year_in_school='HACK')
>>> new_student.year_in_school
'HA'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3299 次 |
最近记录: |