Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - birthdate fildset as form widget

Tags:

forms

django

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

like image 338
krzyhub Avatar asked Jun 25 '11 06:06

krzyhub


2 Answers

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)
like image 163
jarred Avatar answered Oct 09 '22 15:10

jarred


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.

like image 27
jammon Avatar answered Oct 09 '22 16:10

jammon