This commit represents a comprehensive improvement of the library's architecture, developer experience, and documentation accuracy. Core Refactoring: - apply DRY principle to models.py by introducing BaseNepaliBSField and BaseLocationField - standardize widget logic in widgets.py using NepaliWidgetMixin - centralize admin filtering logic into BaseNepaliDateFilter New Features & API: - add NepaliMonthFilter for Django Admin and NepaliDateMonthFilter for DRF - implementation of HTMX-driven location chaining for dynamic address selects - extend demo project with comprehensive DRF search, ordering, and filter examples Configuration & Sync: - implement global NEPKIT settings in conf.py (DEFAULT_LANGUAGE, ADMIN_DATEPICKER, etc.) - universalize BS_DATE_FORMAT/BS_DATETIME_FORMAT across the entire stack - synchronize frontend datepicker initialization with backend date formats Documentation & DX: - complete rewrite of README.md into high-energy, factual, English-only guides - project-wide audit and simplification of comments/docstrings for beginner accessibility - expanded 'Technical Design' and 'FAQ' sections covering data integrity and storage - added docs/migration_guide.py for bulk AD-to-BS data transitions Quality & Maintenance: - fixed all E402 module-level import errors across the library - verified codebase with project-wide ruff checks (all checks passed)
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
from django.contrib import admin
|
|
|
|
from django_nepkit import (
|
|
NepaliModelAdmin,
|
|
NepaliAdminMixin,
|
|
NepaliDateFilter,
|
|
NepaliMonthFilter,
|
|
)
|
|
|
|
from .models import Person, Citizen, AuditedPerson
|
|
|
|
|
|
# Example 1: Basic setup
|
|
@admin.register(Person)
|
|
class PersonAdmin(NepaliModelAdmin):
|
|
list_display = (
|
|
"name",
|
|
"birth_date",
|
|
"birth_date_ne",
|
|
"phone_number",
|
|
"province",
|
|
"province_ne",
|
|
"district",
|
|
"district_ne",
|
|
"municipality",
|
|
"municipality_ne",
|
|
"created_at",
|
|
"updated_at",
|
|
)
|
|
# Added Year and Month filters
|
|
list_filter = (
|
|
("birth_date", NepaliDateFilter),
|
|
("birth_date", NepaliMonthFilter),
|
|
"province",
|
|
)
|
|
search_fields = ("name", "phone_number")
|
|
|
|
|
|
# Example 2: Using a Mixin
|
|
class BaseAuditAdmin(admin.ModelAdmin):
|
|
"""A fake base class for testing."""
|
|
|
|
pass
|
|
|
|
|
|
# Use the Mixin if you already have a base Admin class
|
|
@admin.register(AuditedPerson)
|
|
class CustomPersonAdmin(NepaliAdminMixin, BaseAuditAdmin):
|
|
list_display = ("name", "birth_date", "created_at")
|
|
list_filter = (
|
|
("created_at", NepaliMonthFilter), # Filter by Nepali Month
|
|
)
|
|
|
|
|
|
# Example 3: HTMX support
|
|
@admin.register(Citizen)
|
|
class CitizenAdmin(NepaliModelAdmin):
|
|
list_display = ("name", "province", "district", "municipality")
|
|
# Filters still work with HTMX
|
|
list_filter = ("province", "district")
|