我正在尝试获取所有item.estimated_cost的总数,我可以使用var ...
batches = Batch.objects.for_user_pending(request.user)
total_estimated_cost = 0
for item in batches:
total_estimated_cost =+ item.estimated_cost
但是我收到了这个错误:
一元+的错误操作数类型:'instancemethod'
* 模型方法*
def estimated_cost(self):
return len(self.content) / 160 + 1 * self.group.contact_set.count()
答案 0 :(得分:1)
def estimated_cost(self):
return (int(len(self.content)) / 160) + (1 * int(self.group.contact_set.count()))
batches = Batch.objects.for_user_pending(request.user)
total_estimated_cost = 0
for item in batches:
total_estimated_cost += item.estimated_cost()