How to set default STATUSES
option ?
如何设置默认的STATUSES选项?
class Order(models.Model):
STATUSES = (
(u'E', u'Expected'),
(u'S', u'Sent'),
(u'F', u'Finished'),
)
status = models.CharField(max_length=2, null=True, choices=STATUSES)
1 个解决方案
#1
38
status = models.CharField(max_length=2, null=True, choices=STATUSES, default='E')
or to avoid setting an invalid default if STATUSES changes:
或者,如果STATUSES发生变化,则避免设置无效的默认值:
status = models.CharField(max_length=2, null=True, choices=STATUSES, default=STATUSES[0][0])
#1
38
status = models.CharField(max_length=2, null=True, choices=STATUSES, default='E')
or to avoid setting an invalid default if STATUSES changes:
或者,如果STATUSES发生变化,则避免设置无效的默认值:
status = models.CharField(max_length=2, null=True, choices=STATUSES, default=STATUSES[0][0])