mirror of https://github.com/django/django.git
Fixed #26582 -- Added prettier admin display for list values.
This commit is contained in:
parent
72ff70fba5
commit
ad403ffa45
|
@ -402,7 +402,7 @@ def display_for_field(value, field, empty_value_display):
|
||||||
elif isinstance(field, models.FileField) and value:
|
elif isinstance(field, models.FileField) and value:
|
||||||
return format_html('<a href="{}">{}</a>', value.url, value)
|
return format_html('<a href="{}">{}</a>', value.url, value)
|
||||||
else:
|
else:
|
||||||
return smart_text(value)
|
return display_for_value(value, empty_value_display)
|
||||||
|
|
||||||
|
|
||||||
def display_for_value(value, empty_value_display, boolean=False):
|
def display_for_value(value, empty_value_display, boolean=False):
|
||||||
|
@ -418,6 +418,8 @@ def display_for_value(value, empty_value_display, boolean=False):
|
||||||
return formats.localize(value)
|
return formats.localize(value)
|
||||||
elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
|
elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
|
||||||
return formats.number_format(value)
|
return formats.number_format(value)
|
||||||
|
elif isinstance(value, (list, tuple)):
|
||||||
|
return ', '.join(force_text(v) for v in value)
|
||||||
else:
|
else:
|
||||||
return smart_text(value)
|
return smart_text(value)
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.admin import helpers
|
from django.contrib.admin import helpers
|
||||||
from django.contrib.admin.utils import (
|
from django.contrib.admin.utils import (
|
||||||
NestedObjects, display_for_field, flatten, flatten_fieldsets,
|
NestedObjects, display_for_field, display_for_value, flatten,
|
||||||
label_for_field, lookup_field, quote,
|
flatten_fieldsets, label_for_field, lookup_field, quote,
|
||||||
)
|
)
|
||||||
from django.db import DEFAULT_DB_ALIAS, models
|
from django.db import DEFAULT_DB_ALIAS, models
|
||||||
from django.test import SimpleTestCase, TestCase, override_settings
|
from django.test import SimpleTestCase, TestCase, override_settings
|
||||||
|
@ -195,6 +195,13 @@ class UtilsTests(SimpleTestCase):
|
||||||
display_value = display_for_field(12345, models.IntegerField(), self.empty_value)
|
display_value = display_for_field(12345, models.IntegerField(), self.empty_value)
|
||||||
self.assertEqual(display_value, '12,345')
|
self.assertEqual(display_value, '12,345')
|
||||||
|
|
||||||
|
def test_list_display_for_value(self):
|
||||||
|
display_value = display_for_value([1, 2, 3], self.empty_value)
|
||||||
|
self.assertEqual(display_value, '1, 2, 3')
|
||||||
|
|
||||||
|
display_value = display_for_value([1, 2, 'buckle', 'my', 'shoe'], self.empty_value)
|
||||||
|
self.assertEqual(display_value, '1, 2, buckle, my, shoe')
|
||||||
|
|
||||||
def test_label_for_field(self):
|
def test_label_for_field(self):
|
||||||
"""
|
"""
|
||||||
Tests for label_for_field
|
Tests for label_for_field
|
||||||
|
|
Loading…
Reference in New Issue