

def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
    if (not prepared):
        value = self.get_prep_lookup(lookup_type, value)
    if hasattr(value, 'get_compiler'):
        value = value.get_compiler(connection=connection)
    if (hasattr(value, 'as_sql') or hasattr(value, '_as_sql')):
        if hasattr(value, 'relabel_aliases'):
            return value
        if hasattr(value, 'as_sql'):
            (sql, params) = value.as_sql()
        else:
            (sql, params) = value._as_sql(connection=connection)
        return QueryWrapper(('(%s)' % sql), params)
    if (lookup_type in ['exact', 'gt', 'lt', 'gte', 'lte']):
        return [self._pk_trace(value, 'get_db_prep_lookup', lookup_type, connection=connection, prepared=prepared)]
    if (lookup_type in ('range', 'in')):
        return [self._pk_trace(v, 'get_db_prep_lookup', lookup_type, connection=connection, prepared=prepared) for v in value]
    elif (lookup_type == 'isnull'):
        return []
    raise TypeError(('Related Field has invalid lookup: %s' % lookup_type))

dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/fields/related.py RelatedField.get_db_prep_lookup/original