I have a simple model:
class Atividade(models.Model):
valor_brl = models.DecimalField(max_digits=14, decimal_places=2)
dolar_ref = models.DecimalField(max_digits=14, decimal_places=2)
valor_usd = models.DecimalField(max_digits=14, decimal_places=2)
I create after a method to calculate a new value using the two fields from the model
@property
def valor_usd_novo(self):
valor_usd_novo = self.valor_brl / self.dolar_ref
return valor_usd_novo
If I call {{ valor_usd_novo }}
I get the result I want.
After this I create the save() method, to save valor_usd_novo
result in valor_usd
field from the model.
def save(self, *args, **kwargs):
self.valor_usd = self.valor_usd_novo()
super(Atividade, self).save(*args, **kwargs)
The point is that when I call valor_usd
I got no results and the database do not update with the result from valor_usd_novo
method.
What I missing here?