如何仅通过增加数量来计算产品的总价?

时间:2019-04-01 09:00:54

标签: django django-rest-framework

我有一个托管订单模型,其中我将产品和价格作为其他模型的产品和价格的外键。我只想通过增加数量来计算产品的总价。我只是建立一个休息API来创建订单。请帮我怎么做。

Models.py

class Product(models.Model):

    product_id = models.AutoField(primary_key=True)

    product = ArrayField(models.CharField(max_length=200, blank=True))

    def __str__(self):

        return str(self.product)

class Price(models.Model):

    product = models.ForeignKey('Product',on_delete=models.CASCADE)

    price_id = models.AutoField(primary_key=True)

    price = models.DecimalField(max_digits=50, decimal_places = 5, default=0)


    def __str__(self):

        return "%s" % self.price

class CustOrder(models.Model):

    Customer_id = models.AutoField(primary_key=True)

    CustomerName = models.CharField(max_length=200)

    email = models.EmailField(max_length=70,blank=True, null= True, unique= True)

    gender = models.CharField(max_length=6, choices=GENDER_CHOICES)

    phone = PhoneField(null=False, blank=True, unique=True)

    landmark = models.PointField()

    #landmark = models.TextField(max_length=400, help_text="Enter the landmark", default='Enter landmark')

    houseno = models.IntegerField(default=0)

    #product_name = models.CharField(max_length=200, choices=PRODUCT_CHOICES,default='Boneless chicken')

    # product_id = models.ForeignKey(Product, on_delete=models.CASCADE,related_name='custorder_productid')

    product = models.ManyToManyField(Product, blank=True,related_name='pricetag')

    quantity = models.IntegerField(default=0)

    # price_id = models.ForeignKey(Price)

    price = models.ForeignKey(Price, on_delete=models.SET_NULL, null=True,related_name='pricetag')

    #price = models.DecimalField(max_digits=50, decimal_places=5, default=48.9)

    pay_method = models.CharField(max_length=200,choices=PAYMENT_CHOICES, default='RAZOR PAY')

    city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)

    area = models.ForeignKey(Area, on_delete=models.SET_NULL, null=True)
 def __str__(self):

        return self.CustomerName

0 个答案:

没有答案