重写addüuu运算符以返回元组python/djang时出现问题

2024-04-23 09:56:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我不太清楚问题出在哪里,可能是语法问题,也可能是关于django返回的querysets的一些问题,我不太清楚。在

Class1(models.Model):
    ...
    def __add__(self,other)
        return other + ({'attribute': value}, ..)

我希望类之间的加法将返回一个包含所有对象的元组并放入其中。 因此,我不得不避免sum()函数,因为它在寻找整数。在

^{2}$

我得到一个没有初始值的空序列的TypeError:reduce()。在

UPDATE: My lists were empty. I resolved that and received this error

TypeError: unsupported operand type(s) for +: 'dict' and 'dict' But shouldn't it be appending the tuple and not the dicts?

有什么想法吗?我是不是完全错了?在

谢谢


Tags: andthedjangoselfaddmodelreturnmodels