在模板中,我想显示每个字段(日,月,年)与AboutForm
分开,而不仅仅是一个输入,如下所示:
models.py:
class About(models.Model):
user = models.OneToOneField(User)
dob = models.DateField(null=True, blank=True)
present_address = models.CharField(max_length=150, null=True, blank=True)
permanent_address = models.CharField(max_length=150, null=True, blank=True)
description = models.TextField(null=True, blank=True)
forms.py:
class AboutForm(forms.ModelForm):
class Meta:
model = About
exclude = ('user',)
答案 0 :(得分:3)
您可以使用SelectDateWidget小部件。
from django.forms import extras
...
class AboutForm(forms.ModelForm):
class Meta:
model = About
exclude = ('user',)
widgets = {
'dob': extras.SelectDateWidget(years=range(1900, 2015))
}
感谢Likeon指出这是内置于Django的。