Django-如何加税和计算总额

时间:2019-03-29 00:39:39

标签: django-models aggregate cart tax

我正在尝试根据所请求的门票数量,每张25.00美元的固定价格以及营业税来计算门票的总价。我输入了数量,价格和税金字段,想知道如何查询以获得最终价格?该查询是否需要在模型或视图中?如何将其转换为模板?

class Ticket(models.Model):
venue=models.CharField(max_length=100)
quantity=models.PositiveIntegerField(default=1)
price=models.DecimalField(default=25.00, max_digits=10, decimal_places=2, 
null=True, blank=True)
loop=models.CharField(max_length=100)
ticket_id=CharField(max_length=100)
taxes=DecimalField(default=0.0725, max_digits=10, decimal_places=2, 
null=True, blank=True)
purchaser = models.ForeignKey(User, related_name="purchases", 
on_delete=models.PROTECT)
created_at=models.DateTimeField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)

 @property
 def total(self):
    q= self.price * self.quantity
    t= q *self.taxes
    totalPrice= t + self.price
    return totalPrice

模板为“ {{ticket.total}} –有人可以提供帮助吗?谢谢,谢谢!

0 个答案:

没有答案