Login

Currency Field Admin Integration

Author:
Rupe
Posted:
May 25, 2009
Language:
Python
Version:
1.0
Tags:
internationalization admin i18n currency field babel decimal
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. Currency Form Field by Rupe 5 years, 9 months ago
  2. Currency Widget by Rupe 5 years, 9 months ago
  3. Currency DB Field by Rupe 5 years, 9 months ago
  4. Currency Object by Rupe 5 years, 9 months ago
  5. Lightweight querysets by sardarnl 1 year, 8 months ago

Comments

Please login first before commenting.