diff --git a/tests/modeltests/prefetch_related/models.py b/tests/modeltests/prefetch_related/models.py
index e6e4f89..1dc034f 100644
a
|
b
|
class Bookmark(models.Model):
|
125 | 125 | tags = generic.GenericRelation(TaggedItem) |
126 | 126 | |
127 | 127 | |
| 128 | class Comment(models.Model): |
| 129 | comment = models.TextField() |
| 130 | |
| 131 | # Content-object field |
| 132 | content_type = models.ForeignKey(ContentType) |
| 133 | object_pk = models.TextField() |
| 134 | content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk") |
| 135 | |
| 136 | |
128 | 137 | ## Models for lookup ordering tests |
129 | 138 | |
130 | 139 | |
diff --git a/tests/modeltests/prefetch_related/tests.py b/tests/modeltests/prefetch_related/tests.py
index 0a75727..810791f 100644
a
|
b
|
from django.test import TestCase
|
5 | 5 | |
6 | 6 | from .models import (Author, Book, Reader, Qualification, Teacher, Department, |
7 | 7 | TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, AuthorWithAge, |
8 | | BookWithYear, Person, House, Room, Employee) |
| 8 | BookWithYear, Person, House, Room, Employee, Comment) |
9 | 9 | |
10 | 10 | |
11 | 11 | class PrefetchRelatedTests(TestCase): |
… |
… |
class GenericRelationTests(TestCase):
|
254 | 254 | qs = TaggedItem.objects.prefetch_related('content_object') |
255 | 255 | list(qs) |
256 | 256 | |
| 257 | def test_prefetch_GFK_nonint_pk(self): |
| 258 | Comment.objects.create(comment="awesome", content_object=self.book1) |
| 259 | |
| 260 | # 1 for Comment table, 1 for Book table |
| 261 | with self.assertNumQueries(2): |
| 262 | qs = Comment.objects.prefetch_related('content_object') |
| 263 | [c.content_object for c in qs] |
| 264 | |
| 265 | |
257 | 266 | def test_traverse_GFK(self): |
258 | 267 | """ |
259 | 268 | Test that we can traverse a 'content_object' with prefetch_related() and |
diff --git a/tests/regressiontests/comment_tests/tests/model_tests.py b/tests/regressiontests/comment_tests/tests/model_tests.py
index c7eaa4c..69c1a81 100644
a
|
b
|
class CommentManagerTests(CommentTestCase):
|
49 | 49 | author_comments = list(Comment.objects.for_model(Author.objects.get(pk=1))) |
50 | 50 | self.assertEqual(article_comments, [c1, c3]) |
51 | 51 | self.assertEqual(author_comments, [c2]) |
| 52 | |
| 53 | def testPrefetchRelated(self): |
| 54 | c1, c2, c3, c4 = self.createSomeComments() |
| 55 | # one for comments, one for Articles, one for Author |
| 56 | with self.assertNumQueries(3): |
| 57 | qs = Comment.objects.prefetch_related('content_object') |
| 58 | [c.content_object for c in qs] |