def safe_uuid():
return uuid.uuid4().bytes.encode('base64').rstrip('=\n').replace('/', '_')
class UUIDField(CharField) :
"""
UUIDField stored in 21 Chars
Example: uuid = UUIDField(primary_key=True, editable=False)
"""
description = "UUIDField stored in 21 Chars"
def __init__(self, *args, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 22 )
kwargs['default'] = safe_uuid
CharField.__init__(self, *args, **kwargs)
def deconstruct(self):
name, path, args, kwargs = super(UUIDField, self).deconstruct()
return name, path, args, kwargs
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1c29dfae-6483-465c-939e-f4319120781f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ad 1) I just react to the current implementation, where in the case of other DBMS than PostgreSQL the hex value in 32 chars is stored. In such cases I propose to store it in a smaller amount of 21 characters. ( = storage optimization )
ad 2) web safe representationThe goal is to translate URLs back and forth. E.g. server.com/apiv1/client/uuid/0b043d5842ca4cab9750b705018f4a1f should allow direct mapping to the ORM object. I am not sure whether the current implementation allows that. Or at least the documentation is not clear about it.
Michael, Florian, I understand your remarks.Allow me to explain more.I do not advocate to replace the code by the one posted by me. I rather advocate to improve it.ad 1) I just react to the current implementation, where in the case of other DBMS than PostgreSQL the hex value in 32 chars is stored. In such cases I propose to store it in a smaller amount of 21 characters. ( = storage optimization )
ad 2) web safe representationThe goal is to translate URLs back and forth. E.g. server.com/apiv1/client/uuid/0b043d5842ca4cab9750b705018f4a1f should allow direct mapping to the ORM object. I am not sure whether the current implementation allows that. Or at least the documentation is not clear about it.
ad >> A non-standard, compressed unique value is not a UUID.Base64 is just different encoding, so value wise you still get the same UUID.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/396e017f-3c57-486c-a7d3-6d9f0a2e9d7a%40googlegroups.com.