不能以django形式选择出生日期

时间:2016-05-14 12:54:15

标签: django forms django-forms

问题是,我不明白如何改变选定的年份

例如,我需要从1995年选择年份,而不是从2016年选择

enter image description here

forms.py

class applyForm(forms.Form):
    name = forms.CharField(label='First name', widget=forms.TextInput(attrs={'placeholder': 'Ivanna'}))
    surname = forms.CharField(label='Last name', widget=forms.TextInput(attrs={'placeholder': 'Diachuk'}))
    gender = forms.ChoiceField(widget=forms.RadioSelect, choices=GENDER_CHOICES, label = 'Gender')
    dateOfBirth = forms.DateField(label='Date of birth', widget=forms.SelectDateWidget)
    country = forms.CharField(label='Country of citizenship')
    city = forms.CharField(label='Current city')
    email = forms.EmailField(label='Email')
    placeOfWorkOrStudy = forms.CharField(label='Place of work/study')
    speciality = forms.CharField(label='Speciality')
    motivationMessage = forms.CharField(widget=forms.Textarea, label='Why do you want became a participant?')

1 个答案:

答案 0 :(得分:1)

dateOfBirth = forms.DateField(label='Date of birth', widget=forms.SelectDateWidget(years=range(1995, 2017)))