Files
django-nepkit/example/demo/serializers.py
T
sankalp c6301686cc feat: add Nepali currency support, number-to-words conversion, and REST API enhancements
- Implement NepaliCurrencyField for model-level currency handling.
- Add format_nepali_currency utility with Lakhs/Crores comma formatting and decimal support.
- Implement number_to_nepali_words and english_to_nepali_unicode helper functions.
- Add nepali_currency, nepali_words, and nepali_unicode template filters.
- Enhance REST API (DRF) support:
    - Added NepaliCurrencySerializerField for formatted currency output.
    - Added NepaliLocalizedSerializerMixin for automatic Devanagari field generation.
    - Added flexible NepaliCurrencyRangeFilter and NepaliDateRangeFilter.
- Integrated automatic currency formatting into NepaliModelAdmin.
- Expanded the example demo app with a Transaction model and updated filters.
- Added comprehensive unit tests for formatting, models, and API components.
- Updated documentation (README.md and todo.md) to reflect new features.
2026-01-30 20:06:39 +05:45

38 lines
1.0 KiB
Python

from rest_framework import serializers
from django_nepkit.serializers import (
NepaliDateSerializerField,
NepaliCurrencySerializerField,
NepaliLocalizedSerializerMixin,
)
from .models import Person, Citizen, AuditedPerson, Transaction
class PersonSerializer(NepaliLocalizedSerializerMixin, serializers.ModelSerializer):
birth_date = NepaliDateSerializerField()
class Meta:
model = Person
fields = "__all__"
class TransactionSerializer(NepaliLocalizedSerializerMixin, serializers.ModelSerializer):
amount_formatted = NepaliCurrencySerializerField(source="amount")
class Meta:
model = Transaction
fields = ["id", "title", "amount", "amount_formatted", "date"]
class CitizenSerializer(serializers.ModelSerializer):
class Meta:
model = Citizen
fields = "__all__"
class AuditedPersonSerializer(serializers.ModelSerializer):
birth_date = NepaliDateSerializerField()
class Meta:
model = AuditedPerson
fields = "__all__"