diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2012-10-03 18:53:40 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-10-10 01:15:29 +0300 |
| commit | b625e8272bd41714c838cfda3fb54e1f5177f009 (patch) | |
| tree | 7edc4b667914e12eaf4b2d74c22cdcb4e024d83e /django | |
| parent | a8b1861fc4d0a48b4879af803bba094eef145017 (diff) | |
Moved F() '&' and '|' to .bitand() and .bitor()
Done for consistency with Q() expressions and QuerySet combining. This
will allow usage of '&' and '|' as boolean logical operators in the
future. Refs #16211.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/expressions.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 639ef6ee10..30c44bacde 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -14,9 +14,11 @@ class ExpressionNode(tree.Node): # because it can be used in strings that also # have parameter substitution. - # Bitwise operators - AND = '&' - OR = '|' + # Bitwise operators - note that these are generated by .bitand() + # and .bitor(), the '&' and '|' are reserved for boolean operator + # usage. + BITAND = '&' + BITOR = '|' def __init__(self, children=None, connector=None, negated=False): if children is not None and len(children) > 1 and connector is None: @@ -66,10 +68,20 @@ class ExpressionNode(tree.Node): return self._combine(other, self.MOD, False) def __and__(self, other): - return self._combine(other, self.AND, False) + raise NotImplementedError( + "Use .bitand() and .bitor() for bitwise logical operations." + ) + + def bitand(self, other): + return self._combine(other, self.BITAND, False) def __or__(self, other): - return self._combine(other, self.OR, False) + raise NotImplementedError( + "Use .bitand() and .bitor() for bitwise logical operations." + ) + + def bitor(self, other): + return self._combine(other, self.BITOR, False) def __radd__(self, other): return self._combine(other, self.ADD, True) @@ -88,10 +100,14 @@ class ExpressionNode(tree.Node): return self._combine(other, self.MOD, True) def __rand__(self, other): - return self._combine(other, self.AND, True) + raise NotImplementedError( + "Use .bitand() and .bitor() for bitwise logical operations." + ) def __ror__(self, other): - return self._combine(other, self.OR, True) + raise NotImplementedError( + "Use .bitand() and .bitor() for bitwise logical operations." + ) def prepare_database_save(self, unused): return self |
