diff options
| author | Loic Bistuer <loic.bistuer@sixmedia.com> | 2014-01-22 00:25:33 +0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-01-22 09:13:15 -0500 |
| commit | c3fdeb28fff35573bf86ef04b234c7f5817b0dea (patch) | |
| tree | a68e305a73ef573585f3327b927f498f01ae7f02 /tests/admin_util | |
| parent | a5ec11c4bbb8f82e02871f154b3cfe0008b00a2b (diff) | |
Fixed #21846 -- Made NestedObjects handle related_name with %(app_label)s or %(class)s.
Diffstat (limited to 'tests/admin_util')
| -rw-r--r-- | tests/admin_util/models.py | 15 | ||||
| -rw-r--r-- | tests/admin_util/tests.py | 12 |
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/admin_util/models.py b/tests/admin_util/models.py index 5e86f55a3a..05fb7c4efb 100644 --- a/tests/admin_util/models.py +++ b/tests/admin_util/models.py @@ -47,3 +47,18 @@ class Guest(models.Model): class EventGuide(models.Model): event = models.ForeignKey(Event, on_delete=models.DO_NOTHING) + + +class Vehicle(models.Model): + pass + + +class VehicleMixin(Vehicle): + vehicle = models.OneToOneField(Vehicle, parent_link=True, related_name='vehicle_%(app_label)s_%(class)s') + + class Meta: + abstract = True + + +class Car(VehicleMixin): + pass diff --git a/tests/admin_util/tests.py b/tests/admin_util/tests.py index b978a4ab05..4cb2d843fb 100644 --- a/tests/admin_util/tests.py +++ b/tests/admin_util/tests.py @@ -16,7 +16,7 @@ from django.utils.formats import localize from django.utils.safestring import mark_safe from django.utils import six -from .models import Article, Count, Event, Location, EventGuide +from .models import Article, Count, Event, Location, EventGuide, Vehicle, Car class NestedObjectsTests(TestCase): @@ -80,6 +80,16 @@ class NestedObjectsTests(TestCase): # One for Location, one for Guest, and no query for EventGuide n.collect(objs) + def test_relation_on_abstract(self): + """ + #21846 -- Check that `NestedObjects.collect()` doesn't trip + (AttributeError) on the special notation for relations on abstract + models (related_name that contains %(app_label)s and/or %(class)s). + """ + n = NestedObjects(using=DEFAULT_DB_ALIAS) + Car.objects.create() + n.collect([Vehicle.objects.first()]) + class UtilTests(SimpleTestCase): def test_values_from_lookup_field(self): |
