slashmili / django-jalali

Jalali DateField support for Django model
http://pypi.python.org/pypi/django_jalali
BSD 3-Clause "New" or "Revised" License
258 stars 52 forks source link

Date picker not shown in html template #117

Closed Mehran-Isapour closed 4 years ago

Mehran-Isapour commented 4 years ago

Please provide your configurations and softwares version

Hi. How do I add the jalali date picker to my template?

More details: I used jDatetime field in my model. Then I created a form based on it with ModelForm. I also added the following code to the form: widgets = { 'my_date': widgets.jDateTimeInput } But when the form is rendered on the template, jDateTimeField displaying a textbox instead of a date picker Would you please tell me what to do? Thank you!

hramezani commented 4 years ago

Hi @Mehran-Isapour. Thanks for reporting. I will check it in my free time. It may take some time.

Mehran-Isapour commented 4 years ago

Thank you so much! So I'll wait because I have used it in my project and I am going to finish it. Should I have done anything other than what I wrote above? Thanks again!

hramezani commented 4 years ago

forms.widgets.jDateTimeInput is a form widget not a date picker. If you want to have admin date picker in your form you have to use admin.widgets.AdminSplitjDateTime for DateTimeField and admin.widgets.AdminjDateWidget for DateField. To enable it for your model form first import it:

from django_jalali.admin import widgets

and use it like:

widgets = {'datetime': widgets.AdminSplitjDateTime} 

Then, you need to include admin related js files in your template by:

 <script type="text/javascript" src="/admin/jsi18n/"></script>
 <script type="text/javascript" src="/static/admin/js/core.js"></script>                                                                                                                   
 {{ form.media }}
 {{ form }}
Mehran-Isapour commented 4 years ago

Thanks a lot for your attention. I want to take a date from the user using a date picker and save it in a model instance. (On the normal page that the user sees, not on the site admin page) Is the instruction you wrote what I need to do? or do I need to install a plugin to do it?

hramezani commented 4 years ago

Is the instruction you wrote what I need to do?

Yes, If you want to have Django jalali admin data picker on your form.

I would suggest using another data picker plugin because this is for the admin page

Mehran-Isapour commented 4 years ago

Thank you very much for your guidance.

slashmili commented 4 years ago

I'm closing this issue. Feel free to open it again if you have further questions.

vahidodin commented 3 years ago

forms.widgets.jDateTimeInput is a form widget not a date picker. If you want to have admin date picker in your form you have to use admin.widgets.AdminSplitjDateTime for DateTimeField and admin.widgets.AdminjDateWidget for DateField. To enable it for your model form first import it:

from django_jalali.admin import widgets

and use it like:

widgets = {'datetime': widgets.AdminSplitjDateTime} 

Then, you need to include admin related js files in your template by:

 <script type="text/javascript" src="/admin/jsi18n/"></script>
 <script type="text/javascript" src="/static/admin/js/core.js"></script>                                                                                                                   
 {{ form.media }}
 {{ form }}

hi , sorry i missed up i imported widgets and used inside my ModelAdmin but where should i include these javascript lines ?

{{ form.media }} {{ form }}

thanks for your help

hramezani commented 3 years ago

Hi,

but where should i include these javascript lines ?

in your template file.