简体   繁体   中英

Django save on model

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'

return (Order, self).save(*args, **kwargs)调用父覆盖方法我们使用超级函数你只是调用一个不存在的元组的方法(方法)它应该是return super(Order, self).save(*args, **kwargs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM