'Generates a UUID if self.guid is not already set.'

def assign_uuid(self):

    if (not hasattr(self, 'guid')):
        raise AttributeError('A    UUIDModel    must    contain    a    charfield    called    guid')
    if (not self.guid):
        max_tries = 10
        tried = 1
        guid = str(uuid.uuid4())
        while (tried <= max_tries):
            if (not type(self).objects.filter(guid=guid).exists()):
                self.guid = guid
                break
            else:
                guid = str(uuid.uuid4())
                tried += 1
        else:
            raise ValueError('Could    not    auto-generate    a    unique    UUID')
