django - how to show datepicker calender on datefield -


this regarding how use jquery date picker in django powered site.

models.py is

from django.db import models class holidaytime(models.model):     holiday_date = models.datefield() 

i using jquery datepicker.

i using model form , created text field displaying date sucessfully.

but failed show datepicker icon. using django model forms.

please me in doing this.

thanks in advance.

you can use widget pass class form when rendered in html. class read javascript render datepicker function.

here example:

from django import forms class holidaytimeform(forms.form):     holiday_date = forms.datefield(widget=forms.textinput(attrs=                                 {                                     'class':'datepicker'                                 })) 

... or through widgets attribute in meta class when using modelform:

class holidaytimeform(forms.modelform):      class meta:         model = holiday         widgets = {             'holiday_date': forms.dateinput(attrs={'class':'datepicker'}),         } 

now in template:

 /* include jquery ui here */  <script>   $(function() {     $( ".datepicker" ).datepicker({       changemonth: true,       changeyear: true,       yearrange: "1900:2012",       // can put more options here.      });   });   </script> 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -