如何计算产品属性的总价格 [英] How calculate the total price of a product attribute
本文介绍了如何计算产品属性的总价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
attribute_name = models.CharField(max_length = 200,db_index = True)
price_update =模型。 DecimalField(max_digits = 10,
decimal_places = 2)
类产品(models.Model):
attribute = models.ManyToManyField(attributes)
解决方案
我想你需要
from django.db.models import Sum
Product.objects.filter(id = product_id).aggregate(Sum('attribute__price_update'))
class attributes(models.Model):
attribute_name = models.CharField(max_length = 200, db_index = True)
price_update = models.DecimalField(max_digits = 10,
decimal_places = 2)
class Product(models.Model):
attribute = models.ManyToManyField(attributes)
解决方案
I think you need
from django.db.models import Sum
Product.objects.filter(id=product_id).aggregate(Sum('attribute__price_update'))
这篇关于如何计算产品属性的总价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文