diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index b763b05..6c117f4 100644
a
|
b
|
class RelatedField(object):
|
128 | 128 | # down until we hit a value that can be used for a comparison. |
129 | 129 | v, field = value, None |
130 | 130 | try: |
131 | | while True: |
132 | | v, field = getattr(v, v._meta.pk.name), v._meta.pk |
| 131 | v, field = getattr(v, v._meta.pk.attname), v._meta.pk |
133 | 132 | except AttributeError: |
134 | 133 | pass |
135 | 134 | if field: |
diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
index 06a886e..c006e5f 100644
a
|
b
|
DoesNotExist: ArticleWithAuthor matching query does not exist.
|
267 | 267 | >>> fragment.find('pub_date', pos + 1) == -1 |
268 | 268 | True |
269 | 269 | |
| 270 | >>> from django.conf import settings |
| 271 | >>> settings.DEBUG = True |
| 272 | >>> from django.db import connection, reset_queries |
| 273 | >>> ir = ItalianRestaurant.objects.create(serves_gnocchi=True, serves_pizza=True, serves_hot_dogs=False, name="Django Restaurant") |
| 274 | >>> _ = Supplier.objects.create(restaurant=ir) |
| 275 | >>> ir = ItalianRestaurant.objects.get(pk=ir) |
| 276 | >>> reset_queries() |
| 277 | >>> connection.queries |
| 278 | [] |
| 279 | >>> Supplier.objects.filter(restaurant=ir) |
| 280 | [<Supplier: Supplier object>] |
| 281 | >>> len(connection.queries) |
| 282 | 1 |
| 283 | >>> settings.DEBUG = False |
270 | 284 | """} |