Beispiel #1
0
 def create_sql(self, model, schema_editor, using='', **kwargs):
     include = [model._meta.get_field(field_name).column for field_name in self.include]
     condition = self._get_condition_sql(model, schema_editor)
     if self.expressions:
         index_expressions = []
         for expression in self.expressions:
             index_expression = IndexExpression(expression)
             index_expression.set_wrapper_classes(schema_editor.connection)
             index_expressions.append(index_expression)
         expressions = ExpressionList(*index_expressions).resolve_expression(
             Query(model, alias_cols=False),
         )
         fields = None
         col_suffixes = None
     else:
         fields = [
             model._meta.get_field(field_name)
             for field_name, _ in self.fields_orders
         ]
         col_suffixes = [order[1] for order in self.fields_orders]
         expressions = None
     return schema_editor._create_index_sql(
         model, fields=fields, name=self.name, using=using,
         db_tablespace=self.db_tablespace, col_suffixes=col_suffixes,
         opclasses=self.opclasses, condition=condition, include=include,
         expressions=expressions, **kwargs,
     )
Beispiel #2
0
 def _get_index_expressions(self, model, schema_editor):
     if not self.expressions:
         return None
     index_expressions = []
     for expression in self.expressions:
         index_expression = IndexExpression(expression)
         index_expression.set_wrapper_classes(schema_editor.connection)
         index_expressions.append(index_expression)
     return ExpressionList(*index_expressions).resolve_expression(
         Query(model, alias_cols=False), )
Beispiel #3
0
 def _get_expressions(self, schema_editor, query):
     expressions = []
     for idx, (expression, operator) in enumerate(self.expressions):
         if isinstance(expression, str):
             expression = F(expression)
         try:
             expression = OpClass(expression, self.opclasses[idx])
         except IndexError:
             pass
         expression = ExclusionConstraintExpression(expression, operator=operator)
         expression.set_wrapper_classes(schema_editor.connection)
         expressions.append(expression)
     return ExpressionList(*expressions).resolve_expression(query)