Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #12851 -- Corrected the loading of values when select_related()…

… is used on inherited models. Thanks to phxx for the report and test case.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13054 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4e97d7f8e4acddb2b33d0a1e8bca721ae63d7d7c 1 parent 1ff7ed2
@freakboy3742 freakboy3742 authored
View
2  django/db/models/sql/query.py
@@ -556,7 +556,7 @@ def deferred_to_data(self, target, callback):
# 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)
View
25 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 @@ def __unicode__(self):
>>> 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'
+
+"""}
Please sign in to comment.
Something went wrong with that request. Please try again.