How to save a result of multiplication

23 views
Skip to first unread message

jose angel encinas ramos

unread,
Apr 24, 2021, 2:50:15 PM4/24/21
to Django users
Hi everyone i build a web application in Django 3.1.7 and i try to do the next opeation(multiplication).

in my models a have:
class Articles(models.Model):
     quantity = models.PositiveIntegerField()
    cost_buy = models.DecimalField(max_digits=10, decimal_places=2)
    total_todo = models.DecimalField(max_digits=10, decimal_places=3)

@property
def total_valores(self):
     return (self.cost_buy*self.quantity)

def saveit(self):
    self.total_todo = self.total_valores
    super (Articles, self).save()
__________________________________________________________

so, I was tried with this functions , but it's doesn't save anything

would you give me some recomendations.

Thank you very much in advance and I remain at your service regards

Derek

unread,
Apr 26, 2021, 2:18:20 AM4/26/21
to Django users
I think you have used the wrong name - "saveit" instead of "save" - also have a look at the example in the docs:
and see which parameters are needed for it.

Roberth Solis Martínez

unread,
Apr 26, 2021, 4:42:26 PM4/26/21
to Django users
 I'm according with Derek, but I saw you have a mix of languages and method, spanish and english, I'm speak spanish too, but as a best practice and prevent mix langagues try to use english, you know is like a standard or best practice in latin America
Reply all
Reply to author
Forward
0 new messages