Hi,
Using the django admin application for a date it displays Today | CalendarSymbol
. I am using a datefield in my form and I thought it would do this for me how would i go about doing this? As i would normally use the jquery datepicker plugin is this the way to go?
Thanks in Advance,
Dean
views:
45answers:
2
+1
A:
Usually I do something like this:
class CalendarWidget(forms.TextInput):
class Media:
css = {
'all': ('datepicker.css',)
}
js = ('datepicker.js')
def __init__(self, attrs={}):
super(CalendarWidget, self).__init__(
attrs={'class': 'datepicker',
'size': '14',
'readonly':'readonly'})
class ToDoForm(forms.ModelForm):
class Meta:
model = yourModel
your_date_field = forms.DateTimeField(widget=CalendarWidget)
Finally in your template, something like this:
$(".datepicker").datepicker();
I hope it helps.
juanefren
2010-08-09 16:08:48
And what about the js and CSS mentioned in the widget class do i need to include these or are they already in django?
Dean
2010-08-09 16:16:33
You have to include your calendar media (for example the jquery calendar)... remember to add {{ form.media }} in your <head>
juanefren
2010-08-09 17:04:48
A:
I used the admin like widget in the end was easy to implement plus no external libraries.
Dean
2010-08-11 21:38:57