我的简化模型:
class Product(models.Model):
name = models.CharField()
class Price(models.Model):
product = models.OneToOneField('Product', primary_key=True)
value = models.DecimalField()
class Cart(models.Model):
product = models.ForeignKey('Product')
qnt = models.IntegerField()
我需要将两个字段相乘,即存储在其他字段中sum
。为什么 Cart.objects.select_related('product__price').annotate(sum=F('product__price__value') * F('qnt'))
什么都不返回?
替换F('')
为F('value')
返回错误
无法将关键字“值”解析为字段。选项有:cart_id、id、product、product_id、qnt