diff --git a/tests/modeltests/prefetch_related/models.py b/tests/modeltests/prefetch_related/models.py
index 85488f0..d688800 100644
a
|
b
|
class TaggedItem(models.Model):
|
125 | 125 | related_name='taggeditem_set3') |
126 | 126 | created_by_fkey = models.PositiveIntegerField(null=True) |
127 | 127 | created_by = generic.GenericForeignKey('created_by_ct', 'created_by_fkey',) |
| 128 | favorite_ct = models.ForeignKey(ContentType, null=True, |
| 129 | related_name='taggeditem_set4') |
| 130 | favorite_fkey = models.CharField(max_length=64, null=True) |
| 131 | favorite = generic.GenericForeignKey('favorite_ct', 'favorite_fkey',) |
128 | 132 | |
129 | 133 | def __str__(self): |
130 | 134 | return self.tag |
… |
… |
class TaggedItem(models.Model):
|
132 | 136 | |
133 | 137 | class Bookmark(models.Model): |
134 | 138 | url = models.URLField() |
135 | | tags = generic.GenericRelation(TaggedItem) |
| 139 | tags = generic.GenericRelation(TaggedItem, related_name='bookmarks') |
| 140 | favorite_tags = generic.GenericRelation(TaggedItem, |
| 141 | content_type_field='favorite_ct', |
| 142 | object_id_field='favorite_fkey', |
| 143 | related_name='favorite_bookmarks') |
136 | 144 | |
137 | 145 | |
138 | 146 | class Comment(models.Model): |
diff --git a/tests/modeltests/prefetch_related/tests.py b/tests/modeltests/prefetch_related/tests.py
index 614a5fc..e81560f 100644
a
|
b
|
class GenericRelationTests(TestCase):
|
319 | 319 | for t in b.tags.all()] |
320 | 320 | self.assertEqual(sorted(tags), ["django", "python"]) |
321 | 321 | |
| 322 | def test_charfield_GFK(self): |
| 323 | b = Bookmark.objects.create(url='http://www.djangoproject.com/') |
| 324 | t1 = TaggedItem.objects.create(content_object=b, tag='django') |
| 325 | t2 = TaggedItem.objects.create(content_object=b, favorite=b, tag='python') |
| 326 | |
| 327 | with self.assertNumQueries(3): |
| 328 | bookmark = Bookmark.objects.filter(pk=b.pk).prefetch_related('tags', 'favorite_tags')[0] |
| 329 | self.assertEqual(sorted([i.tag for i in bookmark.tags.all()]), ["django", "python"]) |
| 330 | self.assertEqual([i.tag for i in bookmark.favorite_tags.all()], ["python"]) |
| 331 | |
322 | 332 | |
323 | 333 | class MultiTableInheritanceTest(TestCase): |
324 | 334 | |