diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-30 14:07:47 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-30 14:07:47 +0000 |
| commit | 4e97d7f8e4acddb2b33d0a1e8bca721ae63d7d7c (patch) | |
| tree | 18859ad6b02ba2d3ee2a09fac1a8d0e5c6b339bd /tests | |
| parent | 1ff7ed2e69081eacaa6e160f99beabe35853cb02 (diff) | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/select_related_regress/models.py | 25 |
1 files changed, 24 insertions, 1 deletions
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' + +"""} |
