diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-07-25 16:25:23 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-07-25 16:35:04 +0300 |
| commit | d439f85bbfd9f86dd91e70498ba536394690d1ab (patch) | |
| tree | e8ada87ecdf71424a0d712e634703f8d53ae854a | |
| parent | 76047498719836c7c33c4610afb21b0d000e1393 (diff) | |
[1.6.x] Fixed ._meta.pk_index() virtual field failure
Backport of 92476e880c from master
| -rw-r--r-- | django/db/models/options.py | 5 | ||||
| -rw-r--r-- | tests/foreign_object/models.py | 3 | ||||
| -rw-r--r-- | tests/foreign_object/tests.py | 18 |
3 files changed, 23 insertions, 3 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index ad25de4a3e..ace8f37234 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -204,9 +204,10 @@ class Options(object): def pk_index(self): """ - Returns the index of the primary key field in the self.fields list. + Returns the index of the primary key field in the self.concrete_fields + list. """ - return self.fields.index(self.pk) + return self.concrete_fields.index(self.pk) def setup_proxy(self, target): """ diff --git a/tests/foreign_object/models.py b/tests/foreign_object/models.py index eee8091a15..4c58fd15bd 100644 --- a/tests/foreign_object/models.py +++ b/tests/foreign_object/models.py @@ -140,6 +140,9 @@ class Article(models.Model): except ArticleTranslation.DoesNotExist: return '[No translation found]' +class NewsArticle(Article): + pass + class ArticleTranslation(models.Model): article = models.ForeignKey(Article) lang = models.CharField(max_length='2') diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py index 670fc94dc5..4a7cc3e613 100644 --- a/tests/foreign_object/tests.py +++ b/tests/foreign_object/tests.py @@ -1,7 +1,9 @@ import datetime from operator import attrgetter -from .models import Country, Person, Group, Membership, Friendship, Article, ArticleTranslation, ArticleTag, ArticleIdea +from .models import ( + Country, Person, Group, Membership, Friendship, Article, + ArticleTranslation, ArticleTag, ArticleIdea, NewsArticle) from django.test import TestCase from django.utils.translation import activate from django.core.exceptions import FieldError @@ -339,6 +341,20 @@ class MultiColumnFKTests(TestCase): with self.assertRaises(FieldError): Article.objects.filter(ideas__name="idea1") + def test_inheritance(self): + activate("fi") + na = NewsArticle.objects.create(pub_date=datetime.date.today()) + ArticleTranslation.objects.create( + article=na, lang="fi", title="foo", body="bar") + self.assertQuerysetEqual( + NewsArticle.objects.select_related('active_translation'), + [na], lambda x: x + ) + with self.assertNumQueries(1): + self.assertEqual( + NewsArticle.objects.select_related( + 'active_translation')[0].active_translation.title, + "foo") class FormsTests(TestCase): # ForeignObjects should not have any form fields, currently the user needs |
