mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Fixed #28404 -- Made displaying values in admin respect Field's empty_values.
This commit is contained in:
parent
ec7651586d
commit
9b02ad91ea
1
AUTHORS
1
AUTHORS
@ -47,6 +47,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Aleksandra Sendecka <asendecka@hauru.eu>
|
Aleksandra Sendecka <asendecka@hauru.eu>
|
||||||
Aleksi Häkli <aleksi.hakli@iki.fi>
|
Aleksi Häkli <aleksi.hakli@iki.fi>
|
||||||
Alex Dutton <django@alexdutton.co.uk>
|
Alex Dutton <django@alexdutton.co.uk>
|
||||||
|
Alexander Lazarević <laza@e11bits.com>
|
||||||
Alexander Myodov <alex@myodov.com>
|
Alexander Myodov <alex@myodov.com>
|
||||||
Alexandr Tatarinov <tatarinov.dev@gmail.com>
|
Alexandr Tatarinov <tatarinov.dev@gmail.com>
|
||||||
Alex Aktsipetrov <alex.akts@gmail.com>
|
Alex Aktsipetrov <alex.akts@gmail.com>
|
||||||
|
@ -433,7 +433,7 @@ def display_for_field(value, field, empty_value_display):
|
|||||||
# general null test.
|
# general null test.
|
||||||
elif isinstance(field, models.BooleanField):
|
elif isinstance(field, models.BooleanField):
|
||||||
return _boolean_icon(value)
|
return _boolean_icon(value)
|
||||||
elif value is None:
|
elif value in field.empty_values:
|
||||||
return empty_value_display
|
return empty_value_display
|
||||||
elif isinstance(field, models.DateTimeField):
|
elif isinstance(field, models.DateTimeField):
|
||||||
return formats.localize(timezone.template_localtime(value))
|
return formats.localize(timezone.template_localtime(value))
|
||||||
|
@ -74,15 +74,15 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_tbody_html(obj, href, extra_fields):
|
def build_tbody_html(obj, href, field_name, extra_fields):
|
||||||
return (
|
return (
|
||||||
"<tbody><tr>"
|
"<tbody><tr>"
|
||||||
'<td class="action-checkbox">'
|
'<td class="action-checkbox">'
|
||||||
'<input type="checkbox" name="_selected_action" value="{}" '
|
'<input type="checkbox" name="_selected_action" value="{}" '
|
||||||
'class="action-select" aria-label="Select this object for an action - {}"></td>'
|
'class="action-select" aria-label="Select this object for an action - {}"></td>'
|
||||||
'<th class="field-name"><a href="{}">name</a></th>'
|
'<th class="field-name"><a href="{}">{}</a></th>'
|
||||||
"{}</tr></tbody>"
|
"{}</tr></tbody>"
|
||||||
).format(obj.pk, str(obj), href, extra_fields)
|
).format(obj.pk, str(obj), href, field_name, extra_fields)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF="admin_changelist.urls")
|
@override_settings(ROOT_URLCONF="admin_changelist.urls")
|
||||||
@ -245,7 +245,7 @@ class ChangeListTests(TestCase):
|
|||||||
table_output = template.render(context)
|
table_output = template.render(context)
|
||||||
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
||||||
row_html = build_tbody_html(
|
row_html = build_tbody_html(
|
||||||
new_child, link, '<td class="field-parent nowrap">-</td>'
|
new_child, link, "name", '<td class="field-parent nowrap">-</td>'
|
||||||
)
|
)
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
table_output.find(row_html),
|
table_output.find(row_html),
|
||||||
@ -253,6 +253,24 @@ class ChangeListTests(TestCase):
|
|||||||
"Failed to find expected row element: %s" % table_output,
|
"Failed to find expected row element: %s" % table_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_result_list_empty_changelist_value_blank_string(self):
|
||||||
|
new_child = Child.objects.create(name="", parent=None)
|
||||||
|
request = self.factory.get("/child/")
|
||||||
|
request.user = self.superuser
|
||||||
|
m = ChildAdmin(Child, custom_site)
|
||||||
|
cl = m.get_changelist_instance(request)
|
||||||
|
cl.formset = None
|
||||||
|
template = Template(
|
||||||
|
"{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}"
|
||||||
|
)
|
||||||
|
context = Context({"cl": cl, "opts": Child._meta})
|
||||||
|
table_output = template.render(context)
|
||||||
|
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
||||||
|
row_html = build_tbody_html(
|
||||||
|
new_child, link, "-", '<td class="field-parent nowrap">-</td>'
|
||||||
|
)
|
||||||
|
self.assertInHTML(row_html, table_output)
|
||||||
|
|
||||||
def test_result_list_set_empty_value_display_on_admin_site(self):
|
def test_result_list_set_empty_value_display_on_admin_site(self):
|
||||||
"""
|
"""
|
||||||
Empty value display can be set on AdminSite.
|
Empty value display can be set on AdminSite.
|
||||||
@ -272,7 +290,7 @@ class ChangeListTests(TestCase):
|
|||||||
table_output = template.render(context)
|
table_output = template.render(context)
|
||||||
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
||||||
row_html = build_tbody_html(
|
row_html = build_tbody_html(
|
||||||
new_child, link, '<td class="field-parent nowrap">???</td>'
|
new_child, link, "name", '<td class="field-parent nowrap">???</td>'
|
||||||
)
|
)
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
table_output.find(row_html),
|
table_output.find(row_html),
|
||||||
@ -299,6 +317,7 @@ class ChangeListTests(TestCase):
|
|||||||
row_html = build_tbody_html(
|
row_html = build_tbody_html(
|
||||||
new_child,
|
new_child,
|
||||||
link,
|
link,
|
||||||
|
"name",
|
||||||
'<td class="field-age_display">&dagger;</td>'
|
'<td class="field-age_display">&dagger;</td>'
|
||||||
'<td class="field-age">-empty-</td>',
|
'<td class="field-age">-empty-</td>',
|
||||||
)
|
)
|
||||||
@ -327,7 +346,10 @@ class ChangeListTests(TestCase):
|
|||||||
table_output = template.render(context)
|
table_output = template.render(context)
|
||||||
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
link = reverse("admin:admin_changelist_child_change", args=(new_child.id,))
|
||||||
row_html = build_tbody_html(
|
row_html = build_tbody_html(
|
||||||
new_child, link, '<td class="field-parent nowrap">%s</td>' % new_parent
|
new_child,
|
||||||
|
link,
|
||||||
|
"name",
|
||||||
|
'<td class="field-parent nowrap">%s</td>' % new_parent,
|
||||||
)
|
)
|
||||||
self.assertNotEqual(
|
self.assertNotEqual(
|
||||||
table_output.find(row_html),
|
table_output.find(row_html),
|
||||||
|
@ -159,9 +159,12 @@ class UtilsTests(SimpleTestCase):
|
|||||||
models.TimeField(),
|
models.TimeField(),
|
||||||
]
|
]
|
||||||
for model_field in tests:
|
for model_field in tests:
|
||||||
with self.subTest(model_field=model_field):
|
for value in model_field.empty_values:
|
||||||
display_value = display_for_field(None, model_field, self.empty_value)
|
with self.subTest(model_field=model_field, empty_value=value):
|
||||||
self.assertEqual(display_value, self.empty_value)
|
display_value = display_for_field(
|
||||||
|
value, model_field, self.empty_value
|
||||||
|
)
|
||||||
|
self.assertEqual(display_value, self.empty_value)
|
||||||
|
|
||||||
def test_empty_value_display_choices(self):
|
def test_empty_value_display_choices(self):
|
||||||
model_field = models.CharField(choices=((None, "test_none"),))
|
model_field = models.CharField(choices=((None, "test_none"),))
|
||||||
|
@ -641,7 +641,7 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
|
|||||||
response = self.client.get(reverse("admin:admin_widgets_album_add"))
|
response = self.client.get(reverse("admin:admin_widgets_album_add"))
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
'<div class="readonly"></div>',
|
'<div class="readonly">-</div>',
|
||||||
html=True,
|
html=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user