TAGS :Viewed: 3 - Published at: a few seconds ago

[ SelectDateWidget not getting the correct initial value ]

I'm using userena here and my ProfileForm extends the EditProfileForm(this is a model form) provided by userena

Here's my code in forms.py

class ProfileForm(EditProfileForm):
    contact = forms.CharField(label="Contact Number")
    birthday = forms.DateField(widget=SelectDateWidget(years=reversed(range(1930, datetime.date.today().year))))
    gender = forms.ChoiceField(widget=forms.RadioSelect, choices=GENDER, label="Gender")

    class Meta:
        model = get_profile_model()
        exclude = ['mugshot', 'privacy', 'user']

    def save(self, force_insert=False, force_update=False, commit=True):

From the page rendered, I have date and month showing up fine but year will show 2012(the correct year is 1981) on the page's first load and then another refresh will make the year's select field empty(whyyy? 2012 don't even show up anymore).

I am pretty sure that the data passed in is correct as it shows up fine if I remove the SelectDateWidget. Also, I have checked the type of data passed into the forms and it is correctly typed as datetime.date with the correct value.

My guess is that maybe something is wrong in the SelectDateWidget code, but I can't find any problem there either, plus, I am more suspicious of my own code than other's. Anyone know why this is happening? Data passed in is correct, of this much, I am certain.

EDIT: if it helps, my settings.py contains these

USE_L10N = False

Answer 1

Solved the problem by removing reversed from

birthday = forms.DateField(widget=SelectDateWidget(years=reversed(range(1930, datetime.date.today().year))))

and replace it with

birthday = forms.DateField(widget=SelectDateWidget(years=range(datetime.date.today().year, 1930, -1)))