summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-05-27 11:43:22 -0400
committerTim Graham <timograham@gmail.com>2015-05-28 10:52:50 -0400
commitad0f0daf8c6aa80775d68068a76c5b6d0fff04ec (patch)
tree8879384a693d5e97390beae1e3d3d5868006b3d6
parent80ad5472ce4b6ba6e94227422d0727371e97cdf0 (diff)
Fixed #24851 -- Fixed crash with reverse one-to-one relation in ModelAdmin.list_display
Forwardport of 2456276b0250c9f21d580ca6c3f3c86345ad6370 from stable/1.8.x
-rw-r--r--django/contrib/admin/templatetags/admin_list.py2
-rw-r--r--docs/releases/1.8.3.txt3
-rw-r--r--tests/admin_changelist/admin.py2
-rw-r--r--tests/admin_changelist/models.py4
-rw-r--r--tests/admin_changelist/tests.py11
5 files changed, 17 insertions, 5 deletions
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index affd595800..fe1dee0b0f 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -200,7 +200,7 @@ def items_for_result(cl, result, form):
except ObjectDoesNotExist:
result_repr = EMPTY_CHANGELIST_VALUE
else:
- if f is None:
+ if f is None or f.auto_created:
if field_name == 'action_checkbox':
row_classes = ['action-checkbox']
allow_tags = getattr(attr, 'allow_tags', False)
diff --git a/docs/releases/1.8.3.txt b/docs/releases/1.8.3.txt
index 3bc13a2656..860191db1b 100644
--- a/docs/releases/1.8.3.txt
+++ b/docs/releases/1.8.3.txt
@@ -28,3 +28,6 @@ Bugfixes
* Prevented the loss of ``null``/``not null`` column properties during field
renaming of MySQL databases (:ticket:`24817`).
+
+* Fixed a crash when using a reverse one-to-one relation in
+ ``ModelAdmin.list_display`` (:ticket:`24851`).
diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index bae857f30c..99deafcc62 100644
--- a/tests/admin_changelist/admin.py
+++ b/tests/admin_changelist/admin.py
@@ -107,7 +107,7 @@ site.register(Parent, NoListDisplayLinksParentAdmin)
class SwallowAdmin(admin.ModelAdmin):
actions = None # prevent ['action_checkbox'] + list(list_display)
- list_display = ('origin', 'load', 'speed')
+ list_display = ('origin', 'load', 'speed', 'swallowonetoone')
site.register(Swallow, SwallowAdmin)
diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
index 2b8d2bc7f7..aa4241c4d3 100644
--- a/tests/admin_changelist/models.py
+++ b/tests/admin_changelist/models.py
@@ -83,6 +83,10 @@ class Swallow(models.Model):
ordering = ('speed', 'load')
+class SwallowOneToOne(models.Model):
+ swallow = models.OneToOneField(Swallow)
+
+
class UnorderedObject(models.Model):
"""
Model without any defined `Meta.ordering`.
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index b3c69a37e2..ded3bfc154 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -27,7 +27,7 @@ from .admin import (
from .models import (
Band, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser, Event,
Genre, Group, Invitation, Membership, Musician, OrderedObject, Parent,
- Quartet, Swallow, UnorderedObject,
+ Quartet, Swallow, SwallowOneToOne, UnorderedObject,
)
@@ -547,8 +547,10 @@ class ChangeListTests(TestCase):
Regression test for #17128
(ChangeList failing under Python 2.5 after r16319)
"""
- swallow = Swallow.objects.create(
- origin='Africa', load='12.34', speed='22.2')
+ swallow = Swallow.objects.create(origin='Africa', load='12.34', speed='22.2')
+ swallow2 = Swallow.objects.create(origin='Africa', load='12.34', speed='22.2')
+ swallow_o2o = SwallowOneToOne.objects.create(swallow=swallow2)
+
model_admin = SwallowAdmin(Swallow, custom_site)
superuser = self._create_superuser('superuser')
request = self._mocked_authenticated_request('/swallow/', superuser)
@@ -557,6 +559,9 @@ class ChangeListTests(TestCase):
self.assertContains(response, six.text_type(swallow.origin))
self.assertContains(response, six.text_type(swallow.load))
self.assertContains(response, six.text_type(swallow.speed))
+ # Reverse one-to-one relations should work.
+ self.assertContains(response, '<td class="field-swallowonetoone">-</td>')
+ self.assertContains(response, '<td class="field-swallowonetoone">%s</td>' % swallow_o2o)
def test_deterministic_order_for_unordered_model(self):
"""