Package: django-jalali
This module gives you a DateField same as Django’s DateField but you can
get and query data based on Jalali DateStatusDependenciesjdatetimeDjango> 3.2Looking for Django 1.X support? Checkout2.4.6version in pypi.orgDjango REST Framework> 3.12 (If install withdrfdependency)Installpipinstalldjango_jalaliTo use DRF serializer field:pipinstalldjango_jalali[drf]UsageRun :$django-adminstartprojectjalali_testStart your app :$pythonmanage.pystartappfooEditsettings.pyand add django_jalali and your foo to your INSTALLED_APPS (also config DATABASES setting)django_jalali should be addedbeforeyour apps in order to work properlyEdit foo/models.pyfromdjango.dbimportmodelsfromdjango_jalali.dbimportmodelsasjmodelsclassBar(models.Model):objects=jmodels.jManager()name=models.CharField(max_length=200)date=jmodels.jDateField()def__str__(self):return"%s,%s"%(self.name,self.date)classBarTime(models.Model):objects=jmodels.jManager()name=models.CharField(max_length=200)datetime=jmodels.jDateTimeField()def__str__(self):return"%s,%s"%(self.name,self.datetime)Run$pythonmanage.pymakemigrationsMigrationsfor'foo':foo/migrations/0001_initial.py:-CreatemodelBar-CreatemodelBarTime$pythonmanage.pymigrateRunningmigrations:Applyingfoo.0001_initial...OKTest it$pythonmanage.pyshellPython3.7.0(default,Nov262018,15:26:54)[GCC6.3.020170516]onlinuxType"help","copyright","credits"or"license"formoreinformation.(InteractiveConsole)>>>fromfoo.modelsimportBar>>>importjdatetime>>>today=jdatetime.date(1390,5,12)>>>mybar=Bar(name="foo",date=today)>>>mybar.save()>>>mybar.datejdatetime.date(1390,5,12)>>>Bar.objects.filter(date=today)[<Bar:foo,1390-05-12>]>>>Bar.objects.filter(date__gte="1390-5-12")[<Bar:foo,1390-05-12>]>>>Bar.objects.filter(date='1363-8-01')[]>>>fromfoo.modelsimportBarTime>>>BarTime(name="Bar Time now",datetime=jdatetime.datetime(1380,8,2,12,12,12)).save()>>>BarTime.objects.filter(datetime__date=jdatetime.datetime(1380,8,2,12,12,12))[<BarTime:BarTimenow,1380-08-0212:12:12>]>>>BarTime.objects.filter(datetime__date=jdatetime.date(1380,8,2))[<BarTime:BarTimenow,1380-08-0212:12:12>]>>>BarTime.objects.filter(datetime__date="1380-08-02")[<BarTime:BarTimenow,1380-08-0212:12:12>]>>>BarTime.objects.filter(datetime__lt=jdatetime.datetime(1380,8,2,12,12,12))[]>>>BarTime.objects.filter(datetime__lte=jdatetime.datetime(1380,8,2,12,12,12))[<BarTime:BarTimenow,1380-08-0212:12:12>]>>>BarTime.objects.filter(datetime__gt='1380-08-02')[<BarTime:BarTimenow,1380-08-0212:12:12>]>>>BarTime.objects.filter(datetime__gt=d)[]>>>BarTime.objects.filter(datetime__year=1380)[<BarTime:BarTimenow,1380-08-0212:12:12>]Using TemplatetagsYou can usejformatfilter to format your dates in templates:{%loadjformat%}{{my_date|jformat}}{# default formatting #}{{my_date|jformat:"%A%d%B %Y %H:%M"}}{# specific formatting #}Admin InterfaceCreate foo/admin.pyfromfoo.modelsimportBar,BarTimefromdjango.contribimportadminfromdjango_jalali.admin.filtersimportJDateFieldListFilter# you need import this for adding jalali calander widgetimportdjango_jalali.adminasjadminclassBarAdmin(admin.ModelAdmin):list_filter=(('date',JDateFieldListFilter),)admin.site.register(Bar,BarAdmin)classBarTimeAdmin(admin.ModelAdmin):list_filter=(('datetime',JDateFieldListFilter),)admin.site.register(BarTime,BarTimeAdmin)Config admin interface and fire up your django and enjoy using jalali date !Django rest frameworkThere are serializer fields corresponding tojmodels.JDateFieldandjmodels.JDateTimeFieldfor DRF:fromdjango_jalali.serializers.serializerfieldimportJDateField,JDateTimeFieldfromrest_framework.serializersimportModelSerializerfromfoo.modelsimportBar,BarTimeclassJDateFieldSerialializer(ModelSerializer):date=JDateField()classMeta:model=Barexclude=[]classJDateTimeFieldSerializer(ModelSerializer):datetime=JDateTimeField()classMeta:model=BarTimeexclude=[]LocaleIn order to get the date string in farsi you need to set the locale to fa_IRThere are two ways to do achieve that, you can use of the approaches based on your needsRun server with LC_ALL env:$LC_ALL=fa_IRpythonmanage.pyrunserverSet the locale in settings.pyLANGUAGE_CODE='fa-ir'importlocalelocale.setlocale(locale.LC_ALL,"fa_IR.UTF-8")Timezone SettingsFromdjango_jalaliversion 3 andDjango2 you can useTIME_ZONEandUSE_TZsettingsto save datetime with project timezoneDevelopmentYou can contribute to this project forking it from GitHub and sending pull requests.Firstforktherepositoryand then clone it:$gitclonegit@github.com:<you>/django-jalali.gitInitialize a virtual environment for development purposes:$python-mvenvdjango_jalali_env$source~/django_jalali_env/bin/activateThen install the necessary requirements:$cddjango-jalali$pipinstall-rrequirements-test.txtUnit tests are located in thetestsfolder and can be easily run with the pytest tool:$pytestBefore committing, you can run all the above tests against all supported Python and Django versions with tox.
You need to install tox first:$pipinstalltoxAnd then you can run all tests:$toxIf you wish to limit the testing to specific environment(s), you can parametrize the tox run:$tox-epy39-django32