8

If I have in forms.py:

birthdate = forms.DateTimeField()

and html:

<fieldset class='birthday-picker'>
    <select class='birth-year' name='birth[year]'></select>
    <select class='birth-month' name='birth[month]'></select>
    <select class='birth-day' name='birth[day]'></select>
    <input type='hidden' name='birthdate' />
</fieldset>

Do I need create a new widget or there is an answer for this? If there is no answer i will be grateful for every advice how to do this

krzyhub
  • 6,285
  • 11
  • 42
  • 68

3 Answers3

15

There is a built in widget that already does that.

from django.forms import extras

class SomeForm(forms.ModelForm):
    birthdate = forms.DateField(widget=extras.SelectDateWidget)
jarred
  • 745
  • 2
  • 8
  • 19
1

If the html doesn't have to be exactly like this, you might get away easier with a pure javascript solution like the jquery datepicker or use djangos own admin datewidget.

Community
  • 1
  • 1
jammon
  • 3,404
  • 3
  • 20
  • 29
  • I don't like this datepicker. I like facebook like one: http://plugins.jquery.com/project/birthdaypicker. It seems to I need to work on this a little, but not now. I need sleep, then go. I will use your advices. Thanks. See You later aligatore. – krzyhub Jun 25 '11 at 07:03
0

for version >= 1.9

from django import forms

class Some_Form(forms.Form):
    birthday = forms.DateField(
        widget=forms.SelectDateWidget
        )

or

use jquery-ui

 $(document).ready(function(){
         $('.datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
    })
ryan.chen
  • 33
  • 6