I just want that it will automatic compute when it save on the database
class Order(models.Model):
quantity = models.IntegerField(null=True, blank=True)
price = models.IntegerField(null=True, blank=True)
total_price = models.IntegerField(null=True, blank=True)
def save(self, *args, **kwargs):
self.total_price = self.price * self.quantity
return (Order, self).save(*args, **kwargs)
the error i received is
'tuple' object has no attribute 'save'
CodePudding user response:
return (Order, self).save(*args, **kwargs)
To call parent overriden method we use super function
You're just calling method of a tuple which doesn't exist(the method)
It should be
return super(Order, self).save(*args, **kwargs)