【发布时间】:2012-01-03 11:01:08
【问题描述】:
models.py:
class Foo(models.Model):
...
TIME_UNIT_TYPE = (
('D', 'Day'),
('W', 'Week'),
('M', 'Month'),
)
time_unit = models.CharField(max_length=1, choices=TIME_UNIT_TYPE)
...
forms.py:
class FooForm(ModelForm):
class Meta:
model = Foo
fields = (time_unit,)
当 time_unit 在模板中呈现时,生成的 select 元素 包含我的应用不需要的虚假“----”选项。我可以删除 init() 中的这个虚假选项或重新定义 FooForm 中的 time_unit 属性。但我想知道是否还有其他更直接的方法可以完成同样的任务。
【问题讨论】:
标签: django django-models django-forms