'Set an attribute of an object to a specific value.
Return True if the attribute was changed and False otherwise.'

def _set_attribute(self, obj, attr, value):

    field = obj._meta.get_field_by_name(attr)
    if (len(value) > field[0].max_length):
        cleaned_value = value[:field[0].max_length]
        logger.warn(('The    attribute    "%s"    was    trimmed    from    "%s"    to    "%s"' % (attr, value, cleaned_value)))
    else:
        cleaned_value = value
    old_value = getattr(obj, attr)
    if (cleaned_value != old_value):
        setattr(obj, attr, cleaned_value)
        return True
    return False
