mirror of https://github.com/django/django.git
Refs #29426 -- Made UUIDField render values with dashes.
This commit is contained in:
parent
53ebd4cb13
commit
838d6dcb86
|
@ -1187,7 +1187,7 @@ class UUIDField(CharField):
|
||||||
|
|
||||||
def prepare_value(self, value):
|
def prepare_value(self, value):
|
||||||
if isinstance(value, uuid.UUID):
|
if isinstance(value, uuid.UUID):
|
||||||
return value.hex
|
return str(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
|
|
|
@ -250,6 +250,10 @@ Database backend API
|
||||||
|
|
||||||
* Support for GDAL 1.9 and 1.10 is dropped.
|
* Support for GDAL 1.9 and 1.10 is dropped.
|
||||||
|
|
||||||
|
* To improve readability, the ``UUIDField`` form field now displays values with
|
||||||
|
dashes, e.g. ``550e8400-e29b-41d4-a716-446655440000`` instead of
|
||||||
|
``550e8400e29b41d4a716446655440000``.
|
||||||
|
|
||||||
Miscellaneous
|
Miscellaneous
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,11 @@ class UUIDFieldTest(SimpleTestCase):
|
||||||
value = field.clean('550e8400e29b41d4a716446655440000')
|
value = field.clean('550e8400e29b41d4a716446655440000')
|
||||||
self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
|
self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
|
||||||
|
|
||||||
|
def test_clean_value_with_dashes(self):
|
||||||
|
field = UUIDField()
|
||||||
|
value = field.clean('550e8400-e29b-41d4-a716-446655440000')
|
||||||
|
self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
|
||||||
|
|
||||||
def test_uuidfield_2(self):
|
def test_uuidfield_2(self):
|
||||||
field = UUIDField(required=False)
|
field = UUIDField(required=False)
|
||||||
value = field.clean('')
|
value = field.clean('')
|
||||||
|
@ -24,4 +29,4 @@ class UUIDFieldTest(SimpleTestCase):
|
||||||
def test_uuidfield_4(self):
|
def test_uuidfield_4(self):
|
||||||
field = UUIDField()
|
field = UUIDField()
|
||||||
value = field.prepare_value(uuid.UUID('550e8400e29b41d4a716446655440000'))
|
value = field.prepare_value(uuid.UUID('550e8400e29b41d4a716446655440000'))
|
||||||
self.assertEqual(value, '550e8400e29b41d4a716446655440000')
|
self.assertEqual(value, '550e8400-e29b-41d4-a716-446655440000')
|
||||||
|
|
Loading…
Reference in New Issue