The BooleanField and DecimalField elif
blocks are only included in this snippet to give context in the admin_list.py. Insert the CurrencyField block into the file and the Currency fields will display properly in record lists. If you have all of the objects ( Currency Object, Currency Widget, Currency Form Field, and the Currency DB Field ) then all you have to do is use the DB Field object and the Admin app will (should) work properly.
Please let me know if you have any problems.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Modify: django\contrib\admin\templatetags\admin_list.py
from django.utils.currency import Currency
# Booleans are special: We use images.
elif isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField):
result_repr = _boolean_icon(field_val)
# CurrencyFields are special: use locale currency format.
elif isinstance(f, models.fields.special.CurrencyField):
if field_val is not None:
result_repr = Currency(field_val).format()
else:
result_repr = EMPTY_CHANGELIST_VALUE
# DecimalFields are special: Zero-pad the decimals.
elif isinstance(f, models.DecimalField):
if field_val is not None:
result_repr = ('%%.%sf' % f.decimal_places) % field_val
else:
result_repr = EMPTY_CHANGELIST_VALUE
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 8 months, 3 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months ago
- Serializer factory with Django Rest Framework by julio 1 year, 3 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
- Help text hyperlinks by sa2812 1 year, 5 months ago
Comments
Please login first before commenting.