如何计算产品属性的总价格

时间:2017-04-11 09:44:59

标签: python django

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)

1 个答案:

答案 0 :(得分:1)

我认为你需要

from django.db.models import Sum
Product.objects.filter(id=product_id).aggregate(Sum('attribute__price_update'))