What I'm trying to do is changing the value of an attribute in the serializer (seemed like the appropriate place to change it).
"unsupported operand type(s) for *: 'int' and 'DeferredAttribute'".
This is the error that I'm receiving when doing it my way. Any assistance would be most welcomed.
Models:
class Product(models.Model):
price =models.IntegerField
name=models.CharField(null=True)
In a different app I have the other model
class Order_unit(models.Model):
amount=models.IntegerField
price=models.IntegerField
product=models.ForeignKey(Product)
Serializer:
from order.models import *
from product.models import *
class OrderUnitSerializer(serializers.ModelSerializer):
price= serializers.SerializerMethodField('get_price')
class Meta:
model = Order_unit
fields = ['order', 'product', 'amount', 'price']
def get_price(self,Order_unit):
price= Order_unit.amount*Product.price
return price