Ticket #17186: invert.f.patch

File invert.f.patch, 1.1 KB (added by Andrei Antoukh, 13 years ago)
  • db/models/expressions.py

     
    9898    """
    9999    An expression representing the value of the given field.
    100100    """
     101
     102    self._invert = False
     103
    101104    def __init__(self, name):
    102105        super(F, self).__init__(None, None, False)
    103106        self.name = name
     
    107110        obj.name = self.name
    108111        return obj
    109112
     113    def __invert__(self):
     114        self._invert = True
     115        return self
     116
    110117    def prepare(self, evaluator, query, allow_joins):
    111118        return evaluator.prepare_leaf(self, query, allow_joins)
    112119
    113120    def evaluate(self, evaluator, qn, connection):
    114         return evaluator.evaluate_leaf(self, qn, connection)
     121        evresult = list(evaluator.evaluate_leaf(self, qn, connection))
     122        if self._invert:
     123            evresult[0] = "NOT %s" % evresult[0]
     124        return tuple(evresult)
    115125
     126
    116127class DateModifierNode(ExpressionNode):
    117128    """
    118129    Node that implements the following syntax:
Back to Top