Skip to main content

Django Nepali date, time, phone, and address fields with helpers.

Project description

django-nepkit

PyPI Django 4.2–6.0 Python License

django-nepkit is a lightweight Django utility package for Nepali projects. It provides model fields, validators, and admin helpers for:

  • Bikram Sambat (BS) date, time, and datetime
  • Nepali phone number validation
  • Chained address selects (province → district → municipality)

It also includes Django admin enhancements:

  • NepaliModelAdmin automatically wires the Nepali datepicker
  • NepaliDateFilter for filtering BS dates by year

Optional Django REST Framework (DRF) serializer fields are available (install with django-nepkit[drf]).

Notes


Table of Contents


Installation

pip install django-nepkit

Optional: DRF Serializer Fields

pip install "django-nepkit[drf]"

Requirements

  • Python >=3.11
  • Django >=4.2
  • nepali>=1.1.3

Setup

Add to INSTALLED_APPS

INSTALLED_APPS = [
    # ...
    "django.contrib.staticfiles",
    "django_nepkit",
]

Quick Start

# models.py
from django.db import models
from django_nepkit import NepaliDateField, NepaliDateTimeField, NepaliPhoneNumberField

class Person(models.Model):
    name = models.CharField(max_length=100)
    birth_date = NepaliDateField()
    created_at = NepaliDateTimeField(auto_now_add=True)
    phone_number = NepaliPhoneNumberField()
# admin.py
from django.contrib import admin
from django_nepkit import NepaliModelAdmin
from .models import Person

@admin.register(Person)
class PersonAdmin(NepaliModelAdmin):
    list_display = ("name", "birth_date", "created_at", "phone_number")

NepaliModelAdmin automatically loads the Nepali datepicker assets and applies the widget—no custom forms required.


Model Fields

NepaliDateField (BS date)

Stores a BS date in the DB as a string (YYYY-MM-DD). In Python, it returns/accepts nepali.datetime.nepalidate.

from django_nepkit import NepaliDateField

class Event(models.Model):
    event_date = NepaliDateField()

Notes:

  • Stored as a string, not SQL DATE
  • Accepts BS strings like "2081-10-15", nepalidate, and AD datetime.date (converted to BS)

NepaliDateTimeField (BS datetime)

Stores a BS datetime string (YYYY-MM-DD HH:MM:SS) in the DB and uses nepalidatetime in Python.

from django_nepkit import NepaliDateTimeField

class Log(models.Model):
    created_at = NepaliDateTimeField(auto_now_add=True)
    updated_at = NepaliDateTimeField(auto_now=True)

NepaliTimeField

A normal Django TimeField for consistency.

from django_nepkit import NepaliTimeField

class Shift(models.Model):
    start_time = NepaliTimeField()

NepaliPhoneNumberField

A CharField with Nepali phone number validation.

from django_nepkit import NepaliPhoneNumberField

class Contact(models.Model):
    phone_number = NepaliPhoneNumberField()

Address Fields (Chained Selects)

Chained fields: province → district → municipality.

from django.db import models
from django_nepkit import ProvinceField, DistrictField, MunicipalityField

class Address(models.Model):
    province = ProvinceField()
    district = DistrictField()
    municipality = MunicipalityField()

URLs required for chaining

# urls.py
from django.urls import include, path

urlpatterns = [
    # ...
    path("nepkit/", include("django_nepkit.urls")),
]

Django Admin

NepaliModelAdmin

  • Auto-wires datepicker for BS fields
  • Provides format_nepali_date(...) and format_nepali_datetime(...)
  • Includes NepaliDateFilter
from django.contrib import admin
from django_nepkit import NepaliModelAdmin

@admin.register(MyModel)
class MyModelAdmin(NepaliModelAdmin):
    pass

NepaliDateFilter

Filter NepaliDateField by BS year:

from django_nepkit import NepaliDateFilter, NepaliModelAdmin

@admin.register(MyModel)
class MyModelAdmin(NepaliModelAdmin):
    list_filter = (("my_nepali_date_field", NepaliDateFilter),)

Datepicker assets used:

  • JS: https://nepalidatepicker.sajanmaharjan.com.np/v5/nepali.datepicker/js/nepali.datepicker.v5.0.6.min.js
  • CSS: https://nepalidatepicker.sajanmaharjan.com.np/v5/nepali.datepicker/css/nepali.datepicker.v5.0.6.min.css

Django REST Framework

Install the extra:

pip install "django-nepkit[drf]"

NepaliDateSerializerField

from rest_framework import serializers
from django_nepkit.serializers import NepaliDateSerializerField

class PersonSerializer(serializers.Serializer):
    birth_date = NepaliDateSerializerField(format="%Y/%m/%d")

NepaliDateTimeSerializerField

from rest_framework import serializers
from django_nepkit.serializers import NepaliDateTimeSerializerField

class LogSerializer(serializers.Serializer):
    created_at = NepaliDateTimeSerializerField()

Public API

from django_nepkit import (
    NepaliDateField,
    NepaliTimeField,
    NepaliDateTimeField,
    NepaliPhoneNumberField,
    ProvinceField,
    DistrictField,
    MunicipalityField,
    NepaliDateFilter,
    NepaliModelAdmin,
    NepaliAdminMixin,
)

DRF fields live in django_nepkit.serializers.


Contributing

Contributions are welcome. If you find a bug or want an improvement, please open an issue or submit a pull request.

Local setup

Clone the repo and install dependencies (this project uses uv):

git clone <your-fork-url>
cd prod-django-nepkit
uv sync

Run the example project

The repository contains an example Django project under example/.

cd example
uv run manage.py migrate
uv run manage.py createsuperuser
uv run manage.py runserver

Code quality (recommended before every commit)

Install and run pre-commit:

uv run pre-commit install
uv run pre-commit run --all-files

You can also run Ruff directly:

uv run ruff format .
uv run ruff check .

Pull request guidelines

  • Keep PRs focused and small when possible.
  • Update README.md if behavior or public API changes.
  • If you add a new feature, include a minimal example and tests if applicable.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_nepkit-0.1.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_nepkit-0.1.0-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file django_nepkit-0.1.0.tar.gz.

File metadata

  • Download URL: django_nepkit-0.1.0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for django_nepkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 25268a0da2932f04cbc4c9c2a08ee61683e3896f7f189daf06ca7d039fd4d842
MD5 bdeab2af817fb6a02cbfd0c53bd94c62
BLAKE2b-256 95e2196b8a974f65d75b7b96d46e7da09402308384cd66d6bb1170abcad9c98d

See more details on using hashes here.

File details

Details for the file django_nepkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_nepkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for django_nepkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 935bb2cf012a64088feaa6dcab34b4ccb1c142693a9e20047b275f129ce0837c
MD5 bc70101b49da18c4bf285a78fe356ea4
BLAKE2b-256 f57e1672b9abc7fa4b54de56a78b5167f419cd1d170f2c3898275e0ccf1613c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page