Fixed #24593 -- Fixed number formatting of readonly IntegerFields in the admin.

This commit is contained in:
Eric Rouleau 2015-04-14 17:09:27 -04:00 committed by Simon Charette
parent 6b8c969878
commit d72e0178e9
2 changed files with 7 additions and 1 deletions

View File

@ -385,7 +385,7 @@ def display_for_field(value, field):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)

View File

@ -180,6 +180,9 @@ class UtilsTests(TestCase):
display_value = display_for_field(Decimal('12345.6789'), models.DecimalField())
self.assertEqual(display_value, '12345.6789')
display_value = display_for_field(12345, models.IntegerField())
self.assertEqual(display_value, '12345')
@override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True)
def test_number_formats_with_thousand_seperator_display_for_field(self):
display_value = display_for_field(12345.6789, models.FloatField())
@ -188,6 +191,9 @@ class UtilsTests(TestCase):
display_value = display_for_field(Decimal('12345.6789'), models.DecimalField())
self.assertEqual(display_value, '12,345.6789')
display_value = display_for_field(12345, models.IntegerField())
self.assertEqual(display_value, '12,345')
def test_label_for_field(self):
"""
Tests for label_for_field