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
- Serializer factory with Django Rest Framework by julio 5 months, 3 weeks ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 6 months, 2 weeks ago
- Help text hyperlinks by sa2812 7 months, 1 week ago
- Stuff by NixonDash 9 months, 2 weeks ago
- Add custom fields to the built-in Group model by jmoppel 11 months, 3 weeks ago