class FieldGetDbPrepValueIterableMixin

from django.db.models.lookups import FieldGetDbPrepValueIterableMixin
Some lookups require Field.get_db_prep_value() to be called on each value
in an iterable.

Ancestors (MRO)

  1. builtins.object
  2. django.db.models.lookups.FieldGetDbPrepValueMixin
  3. django.db.models.lookups.FieldGetDbPrepValueIterableMixin
AttributeValueDefined in
def batch_process_rhs(self, compiler, connection, rhs=None)
django.db.models.lookups.FieldGetDbPrepValueIterableMixin
    def batch_process_rhs(self, compiler, connection, rhs=None):
        pre_processed = super().batch_process_rhs(compiler, connection, rhs)
        # The params list may contain expressions which compile to a
        # sql/param pair. Zip them to get sql and param pairs that refer to the
        # same argument and attempt to replace them with the result of
        # compiling the param step.
        sql, params = zip(
            *(
                self.resolve_expression_parameter(compiler, connection, sql, param)
                for sql, param in zip(*pre_processed)
            )
        )
        params = itertools.chain.from_iterable(params)
        return sql, tuple(params)
def get_db_prep_lookup(self, value, connection)
django.db.models.lookups.FieldGetDbPrepValueMixin
    def get_db_prep_lookup(self, value, connection):
        # For relational fields, use the 'target_field' attribute of the
        # output_field.
        field = getattr(self.lhs.output_field, "target_field", None)
        get_db_prep_value = (
            getattr(field, "get_db_prep_value", None)
            or self.lhs.output_field.get_db_prep_value
        )
        return (
            "%s",
            (
                [get_db_prep_value(v, connection, prepared=True) for v in value]
                if self.get_db_prep_lookup_value_is_iterable
                else [get_db_prep_value(value, connection, prepared=True)]
            ),
        )
def get_prep_lookup(self)
django.db.models.lookups.FieldGetDbPrepValueIterableMixin
    def get_prep_lookup(self):
        if hasattr(self.rhs, "resolve_expression"):
            return self.rhs
        prepared_values = []
        for rhs_value in self.rhs:
            if hasattr(rhs_value, "resolve_expression"):
                # An expression will be handled by the database but can coexist
                # alongside real values.
                pass
            elif self.prepare_rhs and hasattr(self.lhs.output_field, "get_prep_value"):
                rhs_value = self.lhs.output_field.get_prep_value(rhs_value)
            prepared_values.append(rhs_value)
        return prepared_values
def process_rhs(self, compiler, connection)
django.db.models.lookups.FieldGetDbPrepValueIterableMixin
    def process_rhs(self, compiler, connection):
        if self.rhs_is_direct_value():
            # rhs should be an iterable of values. Use batch_process_rhs()
            # to prepare/transform those values.
            return self.batch_process_rhs(compiler, connection)
        else:
            return super().process_rhs(compiler, connection)
def resolve_expression_parameter(self, compiler, connection, sql, param)
django.db.models.lookups.FieldGetDbPrepValueIterableMixin
    def resolve_expression_parameter(self, compiler, connection, sql, param):
        params = [param]
        if hasattr(param, "resolve_expression"):
            param = param.resolve_expression(compiler.query)
        if hasattr(param, "as_sql"):
            sql, params = compiler.compile(param)
        return sql, params