Login

Currency Field Admin Integration

Author:
Rupe
Posted:
May 25, 2009
Language:
Python
Version:
1.0
Score:
0 (after 0 ratings)

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

  1. Template tag - list punctuation for a list of items by shapiromatron 8 months, 3 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 3 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
  5. Help text hyperlinks by sa2812 1 year, 5 months ago

Comments

Please login first before commenting.