equal
deleted
inserted
replaced
|
1 from operator import attrgetter |
|
2 |
|
3 from django.test import TestCase |
|
4 |
|
5 from models import Restaurant, Person |
|
6 |
|
7 |
|
8 class ModelInheritanceSelectRelatedTests(TestCase): |
|
9 def test_inherited_select_related(self): |
|
10 # Regression test for #7246 |
|
11 r1 = Restaurant.objects.create( |
|
12 name="Nobu", serves_sushi=True, serves_steak=False |
|
13 ) |
|
14 r2 = Restaurant.objects.create( |
|
15 name="Craft", serves_sushi=False, serves_steak=True |
|
16 ) |
|
17 p1 = Person.objects.create(name="John", favorite_restaurant=r1) |
|
18 p2 = Person.objects.create(name="Jane", favorite_restaurant=r2) |
|
19 |
|
20 self.assertQuerysetEqual( |
|
21 Person.objects.order_by("name").select_related(), [ |
|
22 "Jane", |
|
23 "John", |
|
24 ], |
|
25 attrgetter("name") |
|
26 ) |
|
27 |
|
28 jane = Person.objects.order_by("name").select_related("favorite_restaurant")[0] |
|
29 self.assertEqual(jane.favorite_restaurant.name, "Craft") |