I have a model with an IntegerField and I would like to display the model form for it with a <select> input.
class Education(models.Model):
school = models.CharField(max_length=255)
start_year = models.IntegerField()
end_year = models.IntegerField()
degree = models.CharField(max_length=255, null=True, blank=True)
def __unicode__(self):
display_txt = '%s, (%s - %s)' % (self.school, self.start_year, self.end_year)
return display_txt
class EducationForm(forms.ModelForm):
class Meta:
model = Education
fields = ['school', 'start_year', 'end_year', 'degree']
widgets = {
#'start_year': forms.TextInput(attrs={'placeholder': '2005'}),
#'end_year': forms.TextInput(attrs={'placeholder': '2009'}),
'start_year': forms.ChoiceField(choices=YEAR_CHOICES),
'end_year': forms.ChoiceField(choices=YEAR_CHOICES),
}