'Initialize an empty field with a new UUID before it is saved.'

def pre_save(self, model_instance, add):

    value = getattr(model_instance, self.get_attname(), None)
    if ((not value) and add):
        uuid = str(uuid4())
        setattr(model_instance, self.get_attname(), uuid)
        return uuid
    else:
        return super(UuidField, self).pre_save(model_instance, add)
