0

使用できる変数ですべてのitem.estimated_costのすべての合計を取得しようとしています...

 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()
4

1 に答える 1

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()
于 2013-03-24T14:17:37.547 に答える