我在以下代码行中遇到语法错误。我已经导入了数学,但是我的更新功能仍然无法正常工作。告诉我关键字不能是表达式,并且引用了最后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
filter中使用相关模型使用跨关系的查找

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



因此,您的声明应如下所示:

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

关于python - django语法错误: keyword can't be an expression,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19783998/

10-12 12:43