From cac0a393619dc09905df253e1f11f7c70009ed40 Mon Sep 17 00:00:00 2001 From: Berndt Date: Wed, 9 Jul 2014 20:45:05 +0000 Subject: [PATCH 1/2] fix prefetch related with UUID fields Because the foreign key is stored as a string (char field) and the uuid field is returned as a UUID (StringUUID) object, prefetch related does not work. This patch makes StringUUID dict keys equivelent to string dict keys. --- uuidfield/fields.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/uuidfield/fields.py b/uuidfield/fields.py index 08eb269..837f04b 100644 --- a/uuidfield/fields.py +++ b/uuidfield/fields.py @@ -34,6 +34,17 @@ def __str__(self): def __len__(self): return len(self.__unicode__()) + def __hash__(self): + return self.__unicode__().__hash__() + + def __cmp__(self, other): + # since foreign keys are stored as the hex representation, we + # want to ensure that comparisions are strings without the '-'s + return self.__unicode__().__cmp__(unicode(other).replace('-', '')) + + def __eq__(self, other): + return self.__unicode__().__eq__(unicode(other).replace('-', '')) + class UUIDField(Field): """ From e7ec7de6b823886db1ce54673d03bb5eefde77a6 Mon Sep 17 00:00:00 2001 From: Berndt Date: Thu, 10 Jul 2014 00:14:01 +0000 Subject: [PATCH 2/2] remove the __cmp__ method on StringUUID --- uuidfield/fields.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/uuidfield/fields.py b/uuidfield/fields.py index 837f04b..f95f8bd 100644 --- a/uuidfield/fields.py +++ b/uuidfield/fields.py @@ -37,11 +37,6 @@ def __len__(self): def __hash__(self): return self.__unicode__().__hash__() - def __cmp__(self, other): - # since foreign keys are stored as the hex representation, we - # want to ensure that comparisions are strings without the '-'s - return self.__unicode__().__cmp__(unicode(other).replace('-', '')) - def __eq__(self, other): return self.__unicode__().__eq__(unicode(other).replace('-', ''))