UUIDField compatibility with Python 3

This commit is contained in:
Itai Shirav 2019-06-13 08:58:39 +03:00
parent da87a151df
commit 840b29499a
2 changed files with 4 additions and 2 deletions

View File

@ -461,8 +461,10 @@ class UUIDField(Field):
def to_python(self, value, timezone_in_use):
if isinstance(value, UUID):
return value
elif isinstance(value, binary_type):
return UUID(bytes=value)
elif isinstance(value, string_types):
return UUID(bytes=value) if len(value) == 16 else UUID(value)
return UUID(value)
elif isinstance(value, integer_types):
return UUID(int=value)
elif isinstance(value, tuple):

View File

@ -28,7 +28,7 @@ class UUIDFieldsTest(unittest.TestCase):
'{12345678-1234-5678-1234-567812345678}',
'12345678123456781234567812345678',
'urn:uuid:12345678-1234-5678-1234-567812345678',
'\x12\x34\x56\x78'*4,
b'\x12\x34\x56\x78'*4,
(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678),
0x12345678123456781234567812345678,
UUID(int=0x12345678123456781234567812345678),