'How to use django-jalali calendar in tempates?
Im new to Django and im trying to use django in a Persian app, therefore I need users pick i a date(jalali date) and send it to server. I've used django-jalali in admin area and its working fine, but I need to use this in front-end too. I've set locale to Asia/Tehran and Time Zone to fa but default date picker shows up Gregorian calendar. please help me with that. How can I solve this?
Solution 1:[1]
there is a package called django-jalali-date
which provide you good tools to work with jalali dates. Here is an example of how you can add jalali_date input with datepicker from it's doc
from django import forms
from jalali_date.fields import JalaliDateField, SplitJalaliDateTimeField
from jalali_date.widgets import AdminJalaliDateWidget,
AdminSplitJalaliDateTime
class TestForm(forms.ModelForm):
class Meta:
model = TestModel
fields = ('name', 'date', 'date_time')
def __init__(self, *args, **kwargs):
super(TestForm, self).__init__(*args, **kwargs)
self.fields['date'] = JalaliDateField(label=_('date'), # date format is "yyyy-mm-dd"
widget=AdminJalaliDateWidget # optional, to use default datepicker
)
# you can added a "class" to this field for use your datepicker!
# self.fields['date'].widget.attrs.update({'class': 'jalali_date-date'})
self.fields['date_time'] = SplitJalaliDateTimeField(label=_('date time'),
widget=AdminSplitJalaliDateTime # required, for decompress DatetimeField to JalaliDateField and JalaliTimeField
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohsen Hassani |