我想设置我的订购对象的总额与当时所选产品(order_items)的价格总额。我想在Order构造函数之后立即调用另一个方法,以便在产品价格发生变化时金额不会发生变化
我的订单类别是:
class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.
order_items = models.ManyToManyField(OrderItem, related_name="order_items")
amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
.........
我的OrderItem类是:
class OrderItem(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
........
我的产品类别是:
class Product(models.Model):
name = models.CharField(max_length=30, default=None)
price = models.DecimalField(max_digits=10, decimal_places=2)
product_type = models.ForeignKey(ProductType, on_delete=models.SET_DEFAULT,default = None, null=True, blank=True)
......