how to do total in list elements Python Django

Asked

Viewed 344 times

0

Enter primary data (raw data)where it has values . Flot and I am already calculating the total in function "totalv2" ta run

class Funcionario(models.Model): Custocoleta = models.Decimalfield( max_digits=8, decimalplaces=2, null=False, Blank=False )

CustoIda = models.DecimalField( 
 max_digits=8, 
 decimal_places=2, 
 null=False, 
 blank=False
)

CustoVenda = models.DecimalField( 
 max_digits=8, 
 decimal_places=2, 
 null=False, 
 blank=False 
)

objetos = models.Manager()


def totalv2(self):
  return sum([self.CustoColeta,self.CustoIda,self.NfDeEntrada])

my problem is due to the fact that I need a way to calculate the total (gross) ie take the value of all totalv2 (which is a sub-total) and add up to have the value all freight already made

class conta(models.Model):
def totalfrete(self):
  for x in Funcionario:
    x=sum([self.totalv2])
    return x

a second class was created but I was unsuccessful

1 answer

0


I think you need to review your function a little bit, or we’ll see. The x of the Employee receives the SUM and returns in each iteration (??), if you want the gross you have to sum everything and return at the end of the loop. I think something like that.

def totalfrete(self):
  result = 0
  for x in Funcionario:
    result += (x.CustoColeta + [self.totalv2])
  return result #retorna o resultado no fim, como tinhas retorna em cada iteração o 'x'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.