'Prepare data for addition to the tree. If the data is a list or tuple,
it is expected to be of the form (obj, lookup_type, value), where obj
is a Constraint object, and is then slightly munged before being
stored (to avoid storing any reference to field objects). Otherwise,
the \'data\' is stored unchanged and can be any class with an \'as_sql()\'
method.'

def _prepare_data(self, data):

    if (not isinstance(data, (list, tuple))):
        return data
    (obj, lookup_type, value) = data
    if is_iterator(value):
        value = list(value)
    if (isinstance(value, datetime.datetime) or (isinstance(obj.field, DateTimeField) and (lookup_type != 'isnull'))):
        value_annotation = datetime.datetime
    elif hasattr(value, 'value_annotation'):
        value_annotation = value.value_annotation
    else:
        value_annotation = bool(value)
    if hasattr(obj, 'prepare'):
        value = obj.prepare(lookup_type, value)
    return (obj, lookup_type, value_annotation, value)
