Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
unsuppoted operand type(s) for *: 'NoneType' and 'NoneType'

Helo everyone, am trying to compute unit price and the quantity from this table as follows

class Marketers(models.Model):
    category =models.ForeignKey(Category, on_delete=models.CASCADE, null=True)
    name =models.CharField(max_length=50, null=True, blank =True)
    grade =models.CharField(max_length=50, null=True, blank =True)
    quatity_received = models.IntegerField(default=0, null=True, blank =True)
    unit_price =models.IntegerField(default=0, null=True, blank =True)
    customer = models.CharField(max_length=50, null=True, blank =True)
    date_received = models.DateTimeField(auto_now_add=True)
    date_sold = models.DateTimeField(auto_now_add=True)

    @property
    def get_total(self):
        total = self.quatity_received * self.unit_price
        return total

this is how i call it in my template

<td class="align-middle text-center">
  <span class="text-secondary text-xs font-weight-bold">{{ list.get_total }}</span>
  <p class="text-xs text-secondary mb-0">Overall Price </p>
</td>

this is the erro am receiving

TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

please i need help. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since both quatity_received and unit_price are nullable there is a possibility you are trying to multiply two NoneType together hence the error

TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

Example to recreate the error

[3.8.8] >>> x=None
[3.8.8] >>> x
[3.8.8] >>> x*1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

Solution:

If you are going to have nullable fields try rewriting the get_total function as so

@property
def get_total(self):
    if(self.quatity_received is None and self.unit_price is None):
        return 0
    else:
        return self.quatity_received * self.unit_price
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda