[Fixed]-Django cannot multiply non-int of type 'str'

0👍

I would use this:

def _total_amount(self):
    req = QuoteRow.objects.filter(quote=self.pk)
    return sum([i.unit_price * i.quantity for i in req])

It takes one more line but it’s clearer to me.

1👍

Try using extra()

QuoteRow.objects.filter(quote=self.pk).extra(select = {'total': 'SUM(unit_price * quantity)'},)

Leave a comment