我想覆盖 Django 字段的 +- 运算符:
x+y --> x | y (bitwise or)
x-y --> x & (~y) (almost the inverse of above)
在哪里放置覆盖定义?下面是错误的:
class BitCounter(models.BigIntegerField):
description = "A counter used for statistical calculations"
__metaclass__ = models.SubfieldBase
def __radd__(self, other):
return self | other
def __sub__(self, other):
return self & (^other)