MCPcopy
hub / github.com/django/django / ExpressionWrapper

Class ExpressionWrapper

django/db/models/expressions.py:1548–1581  ·  view source on GitHub ↗

An expression that can wrap another expression so that it can provide extra context to the inner expression, such as the output_field.

Source from the content-addressed store, hash-verified

1546
1547@deconstructible(path="django.db.models.ExpressionWrapper")
1548class ExpressionWrapper(SQLiteNumericMixin, Expression):
1549 """
1550 An expression that can wrap another expression so that it can provide
1551 extra context to the inner expression, such as the output_field.
1552 """
1553
1554 def __init__(self, expression, output_field):
1555 super().__init__(output_field=output_field)
1556 self.expression = expression
1557
1558 def set_source_expressions(self, exprs):
1559 self.expression = exprs[0]
1560
1561 def get_source_expressions(self):
1562 return [self.expression]
1563
1564 def get_group_by_cols(self):
1565 if isinstance(self.expression, Expression):
1566 expression = self.expression.copy()
1567 expression.output_field = self.output_field
1568 return expression.get_group_by_cols()
1569 # For non-expressions e.g. an SQL WHERE clause, the entire
1570 # `expression` must be included in the GROUP BY clause.
1571 return super().get_group_by_cols()
1572
1573 def as_sql(self, compiler, connection):
1574 return compiler.compile(self.expression)
1575
1576 def __repr__(self):
1577 return "{}({})".format(self.__class__.__name__, self.expression)
1578
1579 @property
1580 def allowed_default(self):
1581 return self.expression.allowed_default
1582
1583
1584class NegatedExpression(ExpressionWrapper):

Calls

no outgoing calls