commit faa8ee1bcf49d33f495804f16d9d03a389ae22ae
Author: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Date: Wed Apr 10 07:13:16 2019 +0200
FIxed #30343
diff --git a/tests/prefetch_related/models.py b/tests/prefetch_related/models.py
index 091d600475..b55c92015a 100644
a
|
b
|
class Comment(models.Model):
|
196 | 196 | ordering = ['id'] |
197 | 197 | |
198 | 198 | |
| 199 | class PetUUID(models.Model): |
| 200 | id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) |
| 201 | name = models.CharField(max_length=20) |
| 202 | |
| 203 | |
| 204 | class CommentUUID(models.Model): |
| 205 | comment = models.TextField() |
| 206 | |
| 207 | # Content-object field |
| 208 | content_type = models.ForeignKey(ContentType, models.CASCADE) |
| 209 | object_pk = models.CharField(max_length=40) |
| 210 | content_object = GenericForeignKey(ct_field="content_type", fk_field="object_pk") |
| 211 | |
| 212 | class Meta: |
| 213 | ordering = ['id'] |
| 214 | |
| 215 | |
199 | 216 | # Models for lookup ordering tests |
200 | 217 | |
201 | 218 | class House(models.Model): |
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py
index 24982dda14..ff377a28bb 100644
a
|
b
|
from django.test.utils import CaptureQueriesContext
|
8 | 8 | |
9 | 9 | from .models import ( |
10 | 10 | Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book, Bookmark, |
11 | | BookReview, BookWithYear, Comment, Department, Employee, FavoriteAuthors, |
12 | | House, LessonEntry, ModelIterableSubclass, Person, Qualification, Reader, |
13 | | Room, TaggedItem, Teacher, WordEntry, |
| 11 | BookReview, BookWithYear, Comment, CommentUUID, Department, Employee, |
| 12 | FavoriteAuthors, House, LessonEntry, ModelIterableSubclass, Person, |
| 13 | PetUUID, Qualification, Reader, Room, TaggedItem, Teacher, WordEntry, |
14 | 14 | ) |
15 | 15 | |
16 | 16 | |
… |
… |
class GenericRelationTests(TestCase):
|
885 | 885 | qs = Comment.objects.prefetch_related('content_object') |
886 | 886 | [c.content_object for c in qs] |
887 | 887 | |
| 888 | def test_prefetch_GFK_uuid_pk(self): |
| 889 | pet = PetUUID.objects.create(name='Dog') |
| 890 | CommentUUID.objects.create(comment='awesome', content_object=pet) |
| 891 | qs = CommentUUID.objects.prefetch_related('content_object') |
| 892 | self.assertEqual([c.content_object for c in qs], [pet]) |
| 893 | |
888 | 894 | def test_traverse_GFK(self): |
889 | 895 | """ |
890 | 896 | A 'content_object' can be traversed with prefetch_related() and |