我在Django中有一个包含选择字段的对象
class CustomFieldType(models.Model):
STRING = 'STRING'
DATE = 'DATE'
BOOLEAN = 'BOOLEAN'
NUMERIC = 'NUMERIC'
EMAIL = 'EMAIL'
TYPE_CHOICES = (
(STRING, _('String')),
(DATE, _('Date')),
(BOOLEAN, _('Boolean')),
(NUMERIC, _('Numeric')),
(EMAIL, _('Email'))
)
name = models.CharField(max_length=256)
field_type = models.CharField(choices=TYPE_CHOICES, default=STRING, max_length=10)
company = models.ForeignKey('Company')
class Meta:
unique_together = ('name', 'company')
def __unicode__(self):
return self.name
在我的Django控制台中
$> CustomFieldType.objects.create(name='custom_name',field_type='noError',company=mycompany)
<CustomFieldType: custom_name>
$> CustomFieldType.objects.get(name='custom_name').field_type
u'noError'
为什么Django没有引发错误(ValidationError)?还是我漏掉了什么?