1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

[1.8.x] Fixed #24912 -- Fixed prefetch_related failure for UUIDField primary keys

This resolves a problem on databases besides PostgreSQL when using
prefetch_related with a source model that uses a UUID primary key.

Backport of bfb5b7150f from master
This commit is contained in:
Brian King
2015-06-05 12:40:51 +01:00
committed by Tim Graham
parent 062ce508b0
commit c58755d875
4 changed files with 119 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
import uuid
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
@@ -257,3 +259,18 @@ class Author2(models.Model):
class Meta:
ordering = ['id']
# Models for many-to-many with UUID pk test:
class Pet(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=20)
people = models.ManyToManyField(Person, related_name='pets')
class Flea(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
current_room = models.ForeignKey(Room, related_name='fleas', null=True)
pets_visited = models.ManyToManyField(Pet, related_name='fleas_hosted')
people_visited = models.ManyToManyField(Person, related_name='fleas_hosted')