I’m trying to use UUID on my Django application, as I prefer to share a UUID instead of a simple ID, this way I have external/internal identificators.
I want Django to tell postgres to set a default value to ‘uuid_generate_v4()’
But it’s not obeying my.
I tried to create a callable with this:
def uuid_generate_v4(): """ Generates a random UUID based on postgresql native function. :return: Returns a native UUID. :rtype: UUID """ with connection.cursor() as cursor: cursor.execute("SELECT uuid_generate_v4()") row = cursor.fetchone() return row
I also tried this:
class uuid_generate_v4(models.Func): template = 'uuid_generate_v4()' output_field = models.UUIDField()
But none of it seems to work, is there any way to have a default UUID4 using the uuid-ossp instead of pgcrypto?