0

I select date using DateField and insert date value using this.

 form = DateField(widget=SelectDateWidget(years=BIRTH_YEAR_CHOICES))

and then, I want to show selected value using DateField(form) in HTML from database

 (when create profileForm())
 Birth: selectbox(------), selectbox(------), selectbox(------) 
 : solved

 (if edit profile page using profileForm())
  Birth: selectbox(1987) selectbox(10) selectbox(25)
 -> I want it

How to insert value into DataField, and show selectDateWidget?

Haibane
  • 67
  • 5

1 Answers1

1

Your problem is not too clear.

You should post more information from you forms.py and your views.py. Are you using forms.Form or forms.ModelForm?

Either way I think your question is about using initial data in your form.

Note that this field in particular accepts a python datetime object (see: http://docs.python.org/2/library/datetime.html).

https://docs.djangoproject.com/en/dev/ref/forms/api/#dynamic-initial-values Use is like this:

f = ContactForm(initial={'my_date_field': datetime.datetime.now()})

If you are using ModelForm is is like this:

f = ContactForm(instance=Contact.objects.get(pk=1))

This will initialise all the values from the models (and thus database).

Williams
  • 4,044
  • 1
  • 37
  • 53
  • 1
    Thank's your advice. problem is solved. I make tuple. YEARS={'a','b','c','d','e'...) and ~~Field(label='~', widget='~', choices=YEARS) – Haibane Jan 11 '13 at 07:21