Raisul Islam
Raisul Islam

Reputation: 1581

How calculate the total price of a product attribute

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)

Upvotes: 0

Views: 234

Answers (1)

itzMEonTV
itzMEonTV

Reputation: 20369

I think you need

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

Upvotes: 1

Related Questions