diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 38806e7..b655990 100644
a
|
b
|
class SQLCompiler(object):
|
647 | 647 | else None) |
648 | 648 | columns, aliases = self.get_default_columns(start_alias=alias, |
649 | 649 | opts=model._meta, as_pairs=True, from_parent=from_parent) |
| 650 | |
| 651 | fields = [] |
| 652 | for field, field_model in model._meta.get_concrete_fields_with_model(): |
| 653 | if from_parent and field_model is not None and issubclass(from_parent, field_model): |
| 654 | # Avoid loading data for already loaded parents. |
| 655 | continue |
| 656 | fields.append(field) |
| 657 | |
650 | 658 | self.query.related_select_cols.extend( |
651 | 659 | SelectInfo(col, field) for col, field |
652 | | in zip(columns, model._meta.concrete_fields)) |
| 660 | in zip(columns, fields)) |
653 | 661 | next = requested.get(f.related_query_name(), {}) |
654 | 662 | self.fill_related_selections(model._meta, alias, cur_depth + 1, |
655 | 663 | next, restricted) |
diff --git a/tests/select_related_regress/models.py b/tests/select_related_regress/models.py
index c2611b4..102f1e8 100644
a
|
b
|
class C(Base):
|
154 | 154 | c_a = models.ForeignKey(A) |
155 | 155 | c_b = models.ForeignKey(B) |
156 | 156 | is_published = models.BooleanField(default=False) |
| 157 | |
| 158 | |
| 159 | class Place(models.Model): |
| 160 | name = models.CharField(max_length=50) |
| 161 | address = models.CharField(max_length=80) |
| 162 | |
| 163 | class Restaurant(Place): |
| 164 | serves_hot_dogs = models.BooleanField(default=False) |
| 165 | serves_pizza = models.BooleanField(default=False) |
diff --git a/tests/select_related_regress/tests.py b/tests/select_related_regress/tests.py
index 78d5838..9f80667 100644
a
|
b
|
from django.utils import six
|
5 | 5 | |
6 | 6 | from .models import (Building, Child, Device, Port, Item, Country, Connection, |
7 | 7 | ClientStatus, State, Client, SpecialClient, TUser, Person, Student, |
8 | | Organizer, Class, Enrollment, Hen, Chick, A, B, C) |
| 8 | Organizer, Class, Enrollment, Hen, Chick, A, B, C, Place, Restaurant) |
9 | 9 | |
10 | 10 | |
11 | 11 | class SelectRelatedRegressTests(TestCase): |
… |
… |
class SelectRelatedRegressTests(TestCase):
|
188 | 188 | self.assertEqual(qs_c.c_b.lots_of_text, 'lots_of_text_b') |
189 | 189 | self.assertEqual(qs_c.c_a.name, 'a') |
190 | 190 | self.assertEqual(qs_c.c_b.name, 'b') |
| 191 | |
| 192 | def test_ticket_21413(self): |
| 193 | Restaurant.objects.create(name='Bobs Cafe', address="Somewhere", |
| 194 | serves_pizza=True, serves_hot_dogs=True) |
| 195 | restaurant = Place.objects.all().select_related('restaurant')[0].restaurant |
| 196 | self.assertIsInstance(restaurant.serves_pizza, bool) |
| 197 | self.assertIsInstance(restaurant.serves_hot_dogs, bool) |
| 198 | |