python – django语法错误:关键字不能是表达式

我在以下代码行中遇到语法错误.我已导入数学,但我的更新功能仍无效.告诉我关键字不能是一个表达,并列举底部3行.知道我做错了什么吗?

StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = liquorID.ShelfPrice)

StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = (float(liquorID.OffPremisePrice)) + (float(S750Increase)))

StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = (float(liquorID.OffPremisePrice) * (float(S750Increase)/100)) + float(liquorID.OffPremisePrice))

最佳答案 你不能在参数名中使用点,所以这部分liquorID.BottleSize =’750 ML’会导致SyntaxError

在过滤器中使用相关模型使用跨越关系的查找

https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships

Django offers a powerful and intuitive way to “follow” relationships in lookups, taking care of the SQL JOINs for you automatically, behind the scenes. To span a relationship, just use the field name of related fields across models, separated by double underscores, until you get to the field you want.

所以你的陈述应该是这样的:

StoreLiquor.objects.filter(storeID=ID_Store, 
                           liquorID__BottleSize='750 ML',
                           custom=False).update(StorePrice=liquorID__ShelfPrice)
点赞