Ticket #13963: admin_related_obj_test.diff

File admin_related_obj_test.diff, 1.9 KB (added by Dougal Matthews, 14 years ago)

Tests only that show the error before the patch

  • tests/regressiontests/admin_util/models.py

    diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
    index 493e127..a66a615 100644
    a b  
    11from django.db import models
    22
    3 
    4 
    53class Article(models.Model):
    64    """
    75    A simple Article model for testing
    class Article(models.Model):  
    2018
    2119class Count(models.Model):
    2220    num = models.PositiveSmallIntegerField()
     21
     22
     23class Event(models.Model):
     24    date = models.DateTimeField(auto_now_add=True)
     25
     26class Location(models.Model):
     27    event = models.OneToOneField(Event, verbose_name='event')
  • tests/regressiontests/admin_util/tests.py

    diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
    index 5ea0ac5..2169e05 100644
    a b from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE  
    1212from django.contrib.sites.models import Site
    1313from django.contrib.admin.util import NestedObjects
    1414
    15 from models import Article, Count
     15from models import Article, Count, Event, Location
    1616
    1717
    1818class NestedObjectsTests(TestCase):
    class UtilTests(unittest.TestCase):  
    220220            ),
    221221            ("not Really the Model", MockModelAdmin.test_from_model)
    222222        )
     223   
     224    def test_related_name(self):
     225        """
     226        Regression test for #13963:
     227        """
     228        class EventAdmin(admin.ModelAdmin):
     229            list_display = ('date', 'location', 'organiser')  # Reverse OneToOneField lookup
     230        admin.site.register(Event, EventAdmin)
     231       
     232        self.assertEquals(
     233            label_for_field('location', Event, None, True),
     234            ('location', None),
     235        )
     236       
     237        self.assertEquals(
     238            label_for_field('event', Location, None, True),
     239            ('event', None),
     240        )
     241 No newline at end of file
Back to Top