python - how to show datepicker calender on datefield in crispy forms? -
i new django. create model form shows calender (datepicker) on admin side
but when use crispy form in template file regular field no datepicker
i unable find out solution kindly me here code
model.py
class jobpost(models.model): item_types = ( ('full time',_('full time')), ('part time',_('part time')), ('contract',_('contract')), ) post_type= ( ('job',_('job')), ('classified',_('classified')), ('project/task',_('project/task')), ('internship',_('internship')), ) #user = models.foreignkey(user) job_id = models.autofield(primary_key=true) #user = models.foreignkey(user, editable = false) post_type = models.charfield(verbose_name=_('post type'),max_length=255,null=true, choices=post_type,default='job') job_type = models.charfield(verbose_name=_('job type'),max_length=255,null=true, choices=item_types,default='full time') job_location = models.charfield(verbose_name=_('job location'),max_length=255,null=true) job_title = models.charfield(verbose_name=_('job title'),max_length=255,null=true) job_description = models.textfield(verbose_name=_('job description'),null=true) start_date = models.datefield(verbose_name=_('start date') ,null=true)#4 april 2013 end_date = models.datefield(verbose_name=_('end date'),null=true) how_to_apply = models.charfield(verbose_name=_('how apply'),max_length=255,null=true)
here widgets in model.py
widgets = { 'job_type':radioselect(), 'job_location':textinput(attrs={'size':'70'}), 'job_description':textarea(attrs={'cols':200, 'rows':10}), 'start_date':dateinput(attrs={ 'class': 'datepicker', 'data-date-format': 'yyyy/mm/dd', }), 'end_date':dateinput(attrs={ 'class': 'datepicker', 'data-date-format': 'yyyy/mm/dd', }), }
here using form im template
<head> {% extends "portal/site_base.html" %} {% load crispy_forms_tags %} <p>step {{ step }} of {{ step_count }}</p> {% comment %} {% load i18n %} {% trans "main page of portal." %} {% endcomment %} {% block content %} <meta http-equiv="content-language" content="en-us" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>welcome {{ user.username }} </title> <script type="text/javascript" src="{{ media_url }}js/jquery-min.js"></script> <!-- give correct location jquery.js --> <script type="text/javascript" src="{{ media_url }}js/jquery-ui-min.js"></script> <!-- give correct location jquery-ui.js --> <script type="text/javascript"> $(document).ready(function() { $('.dateinput').datepicker({ format: "yyyy/mm/dd" }); }); </script> </head> {{ post_type_value }} <body> <form method="post" action="/portal/next/post/" class="blueforms" id="id-jobpostform"> {% csrf_token %} {{ post_type_value }} {% crispy form %} {% if request.request.post_type %} <input type="hidden" name="post_type" value="{{ request.request.post_type }}"> {% endif %} {{ post_type_value }} {% field.post_type in form %}{{ field.as_hidden }} <input type="hidden" name="{{ post_type_field }}" value="{{ post_type_value }}" /> {% endfor %}
thats error jquery not working
[08/apr/2013 08:08:02] "get /portal/next/js/jquery-min.js http/1.1" 404 4051 [08/apr/2013 08:08:02] "get /portal/next/js/jquery-ui-min.js http/1.1" 404 4060
i tried level best give different paths jquery not working.
in template, u mentioned class '.dateinput' instead of '.datepicker' u mentioned in widget. try this...
$('.datepicker').datepicker({ format: "yyyy/mm/dd" });
Comments
Post a Comment