Code Monkey home page Code Monkey logo

django-nepali's Introduction

django-nepali

CI status Downloads codecov

A django package on top of nepali python package which supports nepali date time, time conversion, etc on django projects.

Requirements

django
nepali >= 1.0.0

Installation

pip install django-nepali

On settings.py, add 'django_nepali' to your INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'django_nepali',
    ...
]

Django Templates

nepalidatetime

In your Template

{% load nepalidatetime %}

nepalinow

nepalinow renders the current Nepali date and time in 'en-US' locale (English).

For default date format
{% nepalinow %}
For custom date format
{% nepalinow '%Y-%m-%d' %}

nepalinow_ne

nepalinow_ne renders the current Nepali date and time in 'ne' locale (Nepali).

For default date format
{% nepalinow_ne %}
For custom date format
{% nepalinow_ne '%Y-%m-%d' %}

nepalidate

nepalidate renders the datetime object into nepali datetime format in 'en-US' locale (English).

For default date format
{{ datetime_obj|nepalidate }}
For custom date format
{{ datetime_obj|nepalidate:"%Y-%m-%d" }}

nepalidate_ne

nepalidate_ne renders the datetime object into nepali datetime format in 'ne' locale (Nepali).

For default date format
{{ datetime_obj|nepalidate_ne }}
For custom date format
{{ datetime_obj|nepalidate_ne:"%Y-%m-%d" }}

nepalihumanize

nepalihumanize renders the datetime object to a human readable form for 'ne' locale (Nepali)

{{ datetime_obj|nepalihumanize }}
Humanize threshold

You can provide a threshold input, measured in seconds, to the nepalihumanize filter. If the time difference between the current time and the datetime_obj is greater than the specified threshold, then instead of relative time as provided by the humanize function, the datetime_obj will be displayed in the specified format (if provided), or else in the default format.

{{ datetime_obj|nepalihumanize:1000 }}

nepalinumber

In your Template

{% load nepalinumber %}

nepalinumber renders the english number into nepali format (devanagari)

{{ forloop.counter|nepalinumber }}
{{ 150|nepalinumber }}
nepali_comma

Renders the given value with commas added in Nepali style without converting the number.

{{ number|nepali_comma }}

This would convert a number such as 100000 into 1,00,000.

english_comma

Renders the given value with commas added in English style without converting the number.

{{ number|english_comma }}

This would convert a number such as 100000 into 100,000.

nepalinumber with comma

Converts the number into nepali number and renders it. Basically same as {{ number|nepalinumber|nepali_comma }}

{{ number|nepalinumber_with_comma }}

This would convert a number such as 1000 into १,०००.

Contribution

We appreciate feedback and contribution to this package. To get started please see our contribution guide

django-nepali's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-nepali's Issues

Implement NepaliDateField for Django Models and Forms

As an extended package of 'nepali', we need to create a new field called NepaliDateField in Django that supports Nepali dates. This field will be used in both Django models and forms.

Model Usage

Initialization

class MyNepaliInfo(models.Model):
    ...
    birthday = NepaliDateField(...)
    ...

Saving data

This field will support both Python's date and nepalidate.

info = MyNepaliInfo()
info.birthday = nepalidate(2051, 4, 29)  # nepali date
...
info.save()

# OR
info.birthday = datetime.date(1994, 8, 13)  # Python's date

# OR

MyNepaliInfo.objects.create(
    ...
    birthday = nepalidate(2051, 4, 29),
    ...
)

Filtering

Filtering should be done by both Python's date and nepalidate. Also, user should be able to filter with nepali date's year, month, or day.

# filtering with nepalidate
MyNepaliInfo.objects.filter(birthday=nepalidate(2051, 2, 29))

# filtering with Python's date
MyNepaliInfo.objects.filter(birthday=date(1994, 8, 13)

# date range filtering
MyNepaliInfo.objects.filter(birthday__range=(nepalidate1, nepalidate2))
MyNepaliInfo.objects.filter(birthday__gt=nepalidate1)

# Filtering with Nepali year, same goes for the month and day
MyNepaliInfo.objects.filter(birthday__year=2051)

# Filtering with English year
MyNepaliInfo.objects.filter(birthday__year_en=1994)

Form Usage

Initialization

class MyNepaliInfoForm(forms.Form):
    ...
    birthday = NepaliDateFormField(...)
    ...

...

Github Actions implementation for release

Implement Github actions for triggering the release process (eg. building code, compiling docs, publishing package, etc). This Github action should be dependent on the Github release.

Update Community standards

Following Community Standards include:

  • Github Project description
  • Readme document
  • Code of Conduct
  • Contributing document
  • License
  • Security policy
  • Issues templates
  • PR template

Implement NepaliDateTimeField for Django Models and Forms

As an extended package of 'nepali', we need to create a new field called NepaliDateTimeField in Django that supports Nepali dates and times. This field will be used in both Django models and forms.

The implementation will be the same as the implementation of "NepaliDate". Please refer to issue #5

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.