SelectDateWidget doesn't work after reload

28 views
Skip to first unread message

voger

unread,
Dec 15, 2013, 9:48:03 AM12/15/13
to django...@googlegroups.com
I am trying to make a sign up form and there I want to get the users
birth date. I want to use the select date widget. in my models.py I have
set a model field:

birth_date = models.DateField(verbose_name='Birth Date')

and my forms.py looks like this:

from django import forms
from django.forms.extras import SelectDateWidget
from models import UserProfile
import datetime

yearNow = datetime.date.today().year


class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile

localized_fields = ('gender', 'birth_date', 'has_accepted_tos',
'is_18_or_older')
widgets = {
'birth_date': SelectDateWidget(years=reversed(range(yearNow
- 100, yearNow - 18)))
}

The problem is that I don't always get a list of years. The first time I
access the form it works fine. If I reload the form I get a list for the
months, for the days but the list of the years just shows a '---'.

How can I fix this?
Reply all
Reply to author
Forward
0 new messages