Giter VIP home page Giter VIP logo

django-nepali-datetime-field's Introduction

Nepali DateTime Field

Highly motivated package from Django's DateField & DateTimeField. The library is intended to provide Bikram Sambat Date Time fields for Django's Model and Form.

Note: Currently only supports DateField. DateTimeField will be supported soon in future releases.

The package is dependent on nepali-datetime package and the UI for the date picker is implemented from https://github.com/leapfrogtechnology/nepali-date-picker.

Supports: Django 2.0+

Installation

$ pip install django-nepali-datetime-field

Quick start

  1. Add nepali_datetime_field to your INSTALLED_APPS list:

    INSTALLED_APPS = [
        ...
        'nepali_datetime_field',
    ]
    
  2. Importing NepaliDateField model field to models.py file:

    from nepali_datetime_field.models import NepaliDateField
    
    class YourModel(models.Model):
        ...
        nepali_date = NepaliDateField()
    
  3. Importing NepaliDateField form field to forms.py file:

    from nepali_datetime_field.forms import NepaliDateField
    
    class YourForm(forms.Form):
        ...
        nepali_date = NepaliDateField()
    
  4. Whenever using NepaliDateField form field, don't forget to add Widget's media on the <head> section of the html as below:

    <html>
    <head>
    ...
    {{ form.media }}
    ...
    </head>
    <body>
    ...
    {{ form }}
    ...
    </body>
    </html>
    
  5. Querying the model field:

    import nepali_datetime
    
    nepali_date = nepali_datetime.date(1995,10,1)
    
    # get query
    YourModel.objects.get(nepali_date=nepali_date)
    
    # filter query
    YourModel.objects.filter(nepali_date=nepali_date)
    
    # date range query
    from_date = nepali_datetime.date(1990,1,1)
    to_date = nepali_datetime.date(1999,12,30)
    YourModel.objects.filter(nepali_date__range=(from_date, to_date))
    

More Usage

Check some of the usage details in example_app/tests.py.

Demo

Play around with the live demo here.

django-nepali-datetime-field's People

Contributors

amitgaru2 avatar sundaradh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-nepali-datetime-field's Issues

Null and blank true won't work

My model looks below.

from nepali_datetime_field.models import NepaliDateField

created = NepaliDateField(null=True, blank=True)

while I run the migration it gives me the error
AttributeError: 'NoneType' object has no attribute 'to_datetime_date'

Unable to migrate (No module named 'nepali-datetime-field')

Traceback (most recent call last):
File "project/manage.py", line 22, in
main()
File "project/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File ".../lib/python3.9/site-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File ".../lib/python3.9/site-packages/django/core/management/init.py", line 395, in execute
django.setup()
File ".../lib/python3.9/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File ".../lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File ".../lib/python3.9/site-packages/django/apps/config.py", line 224, in create
import_module(entry)
File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'nepali-datetime-field'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.