From d72e0178e9930c9967c6fe6cd8c94b3413a240f9 Mon Sep 17 00:00:00 2001 From: Eric Rouleau Date: Tue, 14 Apr 2015 17:09:27 -0400 Subject: [PATCH] Fixed #24593 -- Fixed number formatting of readonly IntegerFields in the admin. --- django/contrib/admin/utils.py | 2 +- tests/admin_utils/tests.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 69465fa927..f77d848f64 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -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('{}', value.url, value) diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index c41a89eab2..499732cbbb 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -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