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 the value has a relabel_aliases method, it will need to
            # be invoked before the final SQL is evaluated
            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)

        # FIXME: lt and gt are explicitly allowed to make
        # get_(next/prev)_by_date work; other lookups are not allowed since that
        # gets messy pretty quick. This is a good candidate for some refactoring
        # in the future.
        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 is not '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/operator `==` -> `is not`