mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #30343 -- Fixed prefetch_related() for GenericForeignKey when PK of related field is UUIDField.
This commit is contained in:
@@ -7,10 +7,10 @@ from django.test import TestCase, override_settings
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
|
||||
from .models import (
|
||||
Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book, Bookmark,
|
||||
BookReview, BookWithYear, Comment, Department, Employee, FavoriteAuthors,
|
||||
House, LessonEntry, ModelIterableSubclass, Person, Qualification, Reader,
|
||||
Room, TaggedItem, Teacher, WordEntry,
|
||||
Article, Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book,
|
||||
Bookmark, BookReview, BookWithYear, Comment, Department, Employee,
|
||||
FavoriteAuthors, House, LessonEntry, ModelIterableSubclass, Person,
|
||||
Qualification, Reader, Room, TaggedItem, Teacher, WordEntry,
|
||||
)
|
||||
|
||||
|
||||
@@ -885,6 +885,12 @@ class GenericRelationTests(TestCase):
|
||||
qs = Comment.objects.prefetch_related('content_object')
|
||||
[c.content_object for c in qs]
|
||||
|
||||
def test_prefetch_GFK_uuid_pk(self):
|
||||
article = Article.objects.create(name='Django')
|
||||
Comment.objects.create(comment='awesome', content_object_uuid=article)
|
||||
qs = Comment.objects.prefetch_related('content_object_uuid')
|
||||
self.assertEqual([c.content_object_uuid for c in qs], [article])
|
||||
|
||||
def test_traverse_GFK(self):
|
||||
"""
|
||||
A 'content_object' can be traversed with prefetch_related() and
|
||||
|
||||
Reference in New Issue
Block a user