MCPcopy
hub / github.com/django/django / __init__

Method __init__

django/db/models/expressions.py:1641–1659  ·  view source on GitHub ↗
(self, condition=None, then=None, **lookups)

Source from the content-addressed store, hash-verified

1639 conditional = False
1640
1641 def __init__(self, condition=None, then=None, **lookups):
1642 if lookups:
1643 if invalid_kwargs := PROHIBITED_FILTER_KWARGS.intersection(lookups):
1644 invalid_str = ", ".join(f"'{k}'" for k in sorted(invalid_kwargs))
1645 raise TypeError(f"The following kwargs are invalid: {invalid_str}")
1646 if condition is None:
1647 condition, lookups = Q(**lookups), None
1648 elif getattr(condition, "conditional", False):
1649 condition, lookups = Q(condition, **lookups), None
1650 if condition is None or not getattr(condition, "conditional", False) or lookups:
1651 raise TypeError(
1652 "When() supports a Q object, a boolean expression, or lookups "
1653 "as a condition."
1654 )
1655 if isinstance(condition, Q) and not condition:
1656 raise ValueError("An empty Q() can't be used as a When() condition.")
1657 super().__init__(output_field=None)
1658 self.condition = condition
1659 self.result = self._parse_expressions(then)[0]
1660
1661 def __str__(self):
1662 return "WHEN %r THEN %r" % (self.condition, self.result)

Callers

nothing calls this directly

Calls 5

QClass · 0.90
intersectionMethod · 0.45
joinMethod · 0.45
__init__Method · 0.45
_parse_expressionsMethod · 0.45

Tested by

no test coverage detected