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,)
When time_unit is rendered in the template, the resultant select element contains a bogus ‘—-‘ option that I don’t need for my app. I can remove this bogus option inside init() or redefine the time_unit attribute inside the FooForm. But I was wondering if there are any other more straightforward ways to accomplish the same.
Try with:
Test if this works for you.