If I have in forms.py:
birthdate = forms.DateTimeField()
and html:
<fieldset class='birthday-picker'&开发者_运维问答gt;
<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
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)
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.
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' });
})
精彩评论