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)
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from django.db import migrations
|
|
from nepali.datetime import nepalidate
|
|
|
|
|
|
def convert_ad_to_bs(apps, schema_editor):
|
|
"""Logic to convert English (AD) dates to Nepali (BS)."""
|
|
# Set your app and model name here
|
|
MyModel = apps.get_model("YourApp", "YourModel")
|
|
|
|
# Loop through all records and update them
|
|
for obj in MyModel.objects.all():
|
|
# Name of your old and new fields
|
|
if obj.birth_date_ad:
|
|
try:
|
|
# Turn English date into Nepali date
|
|
bs_date = nepalidate.from_date(obj.birth_date_ad)
|
|
# Format the date correctly for the database
|
|
obj.birth_date = bs_date.strftime("%Y-%m-%d")
|
|
obj.save(update_fields=["birth_date"])
|
|
except Exception as e:
|
|
print(f"Error converting object {obj.pk}: {e}")
|
|
|
|
|
|
def reverse_bs_to_ad(apps, schema_editor):
|
|
"""Optional: Logic to convert back to English dates."""
|
|
# Note: BS to AD conversion is also supported by the 'nepali' library.
|
|
pass
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("YourApp", "previous_migration_name"),
|
|
]
|
|
|
|
operations = [
|
|
# 1. Add the new field
|
|
# migrations.AddField(
|
|
# model_name='yourmodel',
|
|
# name='birth_date',
|
|
# field=django_nepkit.models.NepaliDateField(null=True, blank=True),
|
|
# ),
|
|
# 2. Run the conversion
|
|
migrations.RunPython(convert_ad_to_bs, reverse_code=reverse_bs_to_ad),
|
|
# 3. Clean up the old field
|
|
]
|