Code

Ticket #13963: admin_related_obj_test.diff

File admin_related_obj_test.diff, 1.9 KB (added by d0ugal, 4 years ago)

Tests only that show the error before the patch

Line 
1diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
2index 493e127..a66a615 100644
3--- a/tests/regressiontests/admin_util/models.py
4+++ b/tests/regressiontests/admin_util/models.py
5@@ -1,7 +1,5 @@
6 from django.db import models
7 
8-
9-
10 class Article(models.Model):
11     """
12     A simple Article model for testing
13@@ -20,3 +18,10 @@ class Article(models.Model):
14 
15 class Count(models.Model):
16     num = models.PositiveSmallIntegerField()
17+
18+
19+class Event(models.Model):
20+    date = models.DateTimeField(auto_now_add=True)
21+
22+class Location(models.Model):
23+    event = models.OneToOneField(Event, verbose_name='event')
24diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
25index 5ea0ac5..2169e05 100644
26--- a/tests/regressiontests/admin_util/tests.py
27+++ b/tests/regressiontests/admin_util/tests.py
28@@ -12,7 +12,7 @@ from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
29 from django.contrib.sites.models import Site
30 from django.contrib.admin.util import NestedObjects
31 
32-from models import Article, Count
33+from models import Article, Count, Event, Location
34 
35 
36 class NestedObjectsTests(TestCase):
37@@ -220,3 +220,21 @@ class UtilTests(unittest.TestCase):
38             ),
39             ("not Really the Model", MockModelAdmin.test_from_model)
40         )
41+   
42+    def test_related_name(self):
43+        """
44+        Regression test for #13963:
45+        """
46+        class EventAdmin(admin.ModelAdmin):
47+            list_display = ('date', 'location', 'organiser')  # Reverse OneToOneField lookup
48+        admin.site.register(Event, EventAdmin)
49+       
50+        self.assertEquals(
51+            label_for_field('location', Event, None, True),
52+            ('location', None),
53+        )
54+       
55+        self.assertEquals(
56+            label_for_field('event', Location, None, True),
57+            ('event', None),
58+        )
59\ No newline at end of file