[Answer]-Issues with UUID field in django admin

1👍

You may use native Django 1.8 UUIDField. In case you just want always to return non-hyphenated and serialized to string python object, you only have to subclass UUIDField and override from_db_value like this:

class CustomUUIDField(models.UUIDField):

    def from_db_value(self, value, expression, connection, context):
        if isinstance(value, uuid.UUID):
            return value.hex
        else:
            return value

Then use your CustomUUIDField instead native Django’s UUIDField. Remember: this will ONLY work on Django 1.8, not prior versions (nor Django 1.7).

👤danius

Leave a comment