I want to access a product attribute's value. I have defined a product attribute with code weight
and type float
. In my views I'm trying to access it as below:
def red(request):
basket = request.basket
weight_total = 0
for line in basket.all_lines():
weight = line.product.attributes.get(code = 'weight')
weight_total += weight.productattributevalue
It doesn't work and gives error:
'ProductAttribute' object has no attribute 'productattributevalue'
I tried looking into oscar's model but couldn't find the solution. Please help.
I would recommend copying the Django Oscar shipping/scales.py Scale class weigh_product() method.
In there, they use the 'value' property of the product's 'attribute_values' property.