summaryrefslogtreecommitdiff
path: root/tests/model_inheritance_regress
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-04-21 11:50:53 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-04-21 11:50:53 +0200
commit3f01e82c591b880faa5066ba28a3f11b2b82154c (patch)
treef517fd1062ef266f08e8f32ef141599e70a876f2 /tests/model_inheritance_regress
parent3f76339355c1fe550dedf676feddd42a5d48be58 (diff)
downloaddjango-3f01e82c591b880faa5066ba28a3f11b2b82154c.tar.gz
Further consolidated the model_inheritance tests.
Diffstat (limited to 'tests/model_inheritance_regress')
-rw-r--r--tests/model_inheritance_regress/models.py5
-rw-r--r--tests/model_inheritance_regress/tests.py22
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/model_inheritance_regress/models.py b/tests/model_inheritance_regress/models.py
index cb0b2fe72f..48adf94ddf 100644
--- a/tests/model_inheritance_regress/models.py
+++ b/tests/model_inheritance_regress/models.py
@@ -73,9 +73,14 @@ class ParkingLot4B(Place, ParkingLot4):
pass
+@python_2_unicode_compatible
class Supplier(models.Model):
+ name = models.CharField(max_length=50)
restaurant = models.ForeignKey(Restaurant)
+ def __str__(self):
+ return self.name
+
class Wholesaler(Supplier):
retailer = models.ForeignKey(Supplier, related_name='wholesale_supplier')
diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py
index 211877d7c6..5297898e2f 100644
--- a/tests/model_inheritance_regress/tests.py
+++ b/tests/model_inheritance_regress/tests.py
@@ -466,3 +466,25 @@ class ModelInheritanceTest(TestCase):
serves_pizza=True, serves_hot_dogs=True)
p = Place.objects.all().select_related('restaurant')[0]
self.assertIsInstance(p.restaurant.serves_pizza, bool)
+
+ def test_inheritance_select_related(self):
+ # Regression test for #7246
+ r1 = Restaurant.objects.create(
+ name="Nobu", serves_hot_dogs=True, serves_pizza=False
+ )
+ r2 = Restaurant.objects.create(
+ name="Craft", serves_hot_dogs=False, serves_pizza=True
+ )
+ Supplier.objects.create(name="John", restaurant=r1)
+ Supplier.objects.create(name="Jane", restaurant=r2)
+
+ self.assertQuerysetEqual(
+ Supplier.objects.order_by("name").select_related(), [
+ "Jane",
+ "John",
+ ],
+ attrgetter("name")
+ )
+
+ jane = Supplier.objects.order_by("name").select_related("restaurant")[0]
+ self.assertEqual(jane.restaurant.name, "Craft")