Jalali Date support for Django 1.7 and above model and admin interface
Project description
Django Jalali
=============
This module gives you a DateField same as Django’s DateField but you can
get and query data based on Jalali Date
Dependencies
------------
- `jdatetime>=1.5`_ – ``easy_install jdatetime``
- `Django>=1.7`_ – ``easy_install django``
Install
-------
::
$ easy_install django_jalali
Usage
-----
Direct Usage
~~~~~~~~~~~~
#. Run :
::
$ django-admin.py startproject jalali_test
#. Start your app :
::
$ python manage.py startapp foo
#. Edit settings.py and add django\_jalali and your foo to your
INSTALLED\_APPS (also config DATABASES setting)
django\_jalali should be added **before** your apps in order to work
properly
#. Edit foo/models.py
.. code:: python
from django.db import models
from django_jalali.db import models as jmodels
class Bar(models.Model):
objects = jmodels.jManager()
name = models.CharField(max_length=200)
date = jmodels.jDateField()
def __str__(self):
return "%s, %s"%(self.name, self.date)
class BarTime(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
::
$ python manage.py syncdb
#. Test it
.. code:: python
$ python manage.py shell
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from foo.models import Bar
>>> import jdatetime
>>> today = jdatetime.date(1390, 5, 12)
>>> mybar = Bar(name="foo", date=today)
>>> mybar.save()
>>> mybar.date
jdatetime.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-08-01')
[]
>>> from foo.models import BarTime
>>> BarTime(name="Bar Time now", datetime=jdatetime.datetime(1380,8,2,12,12,12)).save()
>>> 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: Bar Time now, 1380-08-0212:12:12>]
>>> BarTime.objects.filter(datetime__gt='1380-08-02')
[<BarTime: Bar Time now, 1380-08-0212:12:12>]
>>> BarTime.objects.filter(datetime__gt=d)
[]
>>> BarTime.objects.filter(datetime__year=1380)
[<BarTime: Bar Time now, 1380-08-0212:12:12>]
Using Templatetags
~~~~~~~~~~~~~~~~~~
#. You can use ``jformat`` filter to format your dates in templates:
.. code:: html
{% load jformat %}
{{ my_date|jformat }} {# default formatting #}
{{ my_date|jformat:"%A %d %B %Y %H:%M" }} {# specific formatting #}
Admin Interface
~~~~~~~~~~~~~~~
#. Create foo/admin.py
.. code:: python
from foo.models import Bar,BarTime
from django.contrib import admin
import django_jalali.admin.filterspecs #you need to import this for adding filter in admin interface
import django_jalali.admin as jadmin #you need import this for adding jalali calander widget
class BarAdmin(admin.ModelAdmin):
list_filter = ['date']
admin.site.register(Bar, BarAdmin)
class BarTimeAdmin(admin.ModelAdmin):
list_filter = ['datetime']
admin.site.register(BarTime, BarTimeAdmin)
#. Config admin interface and fire up your django and enjoy using jalali
date !
.. _.jdatetime: http://pypi.python.org/pypi/jdatetime/
.. _.Django: https://www.djangoproject.com/
=============
This module gives you a DateField same as Django’s DateField but you can
get and query data based on Jalali Date
Dependencies
------------
- `jdatetime>=1.5`_ – ``easy_install jdatetime``
- `Django>=1.7`_ – ``easy_install django``
Install
-------
::
$ easy_install django_jalali
Usage
-----
Direct Usage
~~~~~~~~~~~~
#. Run :
::
$ django-admin.py startproject jalali_test
#. Start your app :
::
$ python manage.py startapp foo
#. Edit settings.py and add django\_jalali and your foo to your
INSTALLED\_APPS (also config DATABASES setting)
django\_jalali should be added **before** your apps in order to work
properly
#. Edit foo/models.py
.. code:: python
from django.db import models
from django_jalali.db import models as jmodels
class Bar(models.Model):
objects = jmodels.jManager()
name = models.CharField(max_length=200)
date = jmodels.jDateField()
def __str__(self):
return "%s, %s"%(self.name, self.date)
class BarTime(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
::
$ python manage.py syncdb
#. Test it
.. code:: python
$ python manage.py shell
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from foo.models import Bar
>>> import jdatetime
>>> today = jdatetime.date(1390, 5, 12)
>>> mybar = Bar(name="foo", date=today)
>>> mybar.save()
>>> mybar.date
jdatetime.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-08-01')
[]
>>> from foo.models import BarTime
>>> BarTime(name="Bar Time now", datetime=jdatetime.datetime(1380,8,2,12,12,12)).save()
>>> 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: Bar Time now, 1380-08-0212:12:12>]
>>> BarTime.objects.filter(datetime__gt='1380-08-02')
[<BarTime: Bar Time now, 1380-08-0212:12:12>]
>>> BarTime.objects.filter(datetime__gt=d)
[]
>>> BarTime.objects.filter(datetime__year=1380)
[<BarTime: Bar Time now, 1380-08-0212:12:12>]
Using Templatetags
~~~~~~~~~~~~~~~~~~
#. You can use ``jformat`` filter to format your dates in templates:
.. code:: html
{% load jformat %}
{{ my_date|jformat }} {# default formatting #}
{{ my_date|jformat:"%A %d %B %Y %H:%M" }} {# specific formatting #}
Admin Interface
~~~~~~~~~~~~~~~
#. Create foo/admin.py
.. code:: python
from foo.models import Bar,BarTime
from django.contrib import admin
import django_jalali.admin.filterspecs #you need to import this for adding filter in admin interface
import django_jalali.admin as jadmin #you need import this for adding jalali calander widget
class BarAdmin(admin.ModelAdmin):
list_filter = ['date']
admin.site.register(Bar, BarAdmin)
class BarTimeAdmin(admin.ModelAdmin):
list_filter = ['datetime']
admin.site.register(BarTime, BarTimeAdmin)
#. Config admin interface and fire up your django and enjoy using jalali
date !
.. _.jdatetime: http://pypi.python.org/pypi/jdatetime/
.. _.Django: https://www.djangoproject.com/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-jalali-2.0.tar.gz
(34.0 kB
view details)
File details
Details for the file django-jalali-2.0.tar.gz
.
File metadata
- Download URL: django-jalali-2.0.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c864a8fa731a3e611c8c2471aa968f4a7c800034face49580bec4bfe3c832e0f |
|
MD5 | 1ebce9c07a292ff5ff80312d422f45a6 |
|
BLAKE2b-256 | 1d881d7f1bc19c8a71f27cb0f43eb8e1f255fe33986dc9e88286760e97bec6b6 |