diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index cfe5d37a37..40faa545c8 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -556,7 +556,7 @@ class Query(object): # models. workset = {} for model, values in seen.iteritems(): - for field in model._meta.local_fields: + for field in model._meta.fields: if field in values: continue add_to_dict(workset, model, field) diff --git a/tests/regressiontests/select_related_regress/models.py b/tests/regressiontests/select_related_regress/models.py index 9eaf934777..c99bee0f7e 100644 --- a/tests/regressiontests/select_related_regress/models.py +++ b/tests/regressiontests/select_related_regress/models.py @@ -65,6 +65,9 @@ class Client(models.Model): state = models.ForeignKey(State, null=True) status = models.ForeignKey(ClientStatus) +class SpecialClient(Client): + value = models.IntegerField() + # Some model inheritance exercises class Parent(models.Model): name = models.CharField(max_length=10) @@ -170,8 +173,28 @@ Exercising select_related() with multi-table model inheritance. >>> wa = State.objects.create(name="Western Australia", country=australia) >>> _ = Client.objects.create(name='Brian Burke', state=wa, status=active) >>> burke = Client.objects.select_related('state').defer('state__name').get(name='Brian Burke') +>>> burke.name +u'Brian Burke' >>> burke.state.name u'Western Australia' -"""} +# Still works if we're dealing with an inherited class +>>> _ = SpecialClient.objects.create(name='Troy Buswell', state=wa, status=active, value=42) +>>> troy = SpecialClient.objects.select_related('state').defer('state__name').get(name='Troy Buswell') +>>> troy.name +u'Troy Buswell' +>>> troy.value +42 +>>> troy.state.name +u'Western Australia' +# Still works if we defer an attribute on the inherited class +>>> troy = SpecialClient.objects.select_related('state').defer('value', 'state__name').get(name='Troy Buswell') +>>> troy.name +u'Troy Buswell' +>>> troy.value +42 +>>> troy.state.name +u'Western Australia' + +"""}