下面的代码行中出现了语法错误。我已经导入了数学,但是我的更新函数仍然不能工作。告诉我关键字不能是一个表达式,并引用最后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))发布于 2013-11-05 07:49:01
您不能使用liquorID.BottleSize,它是无效的。只能使用有效的变量名。:
>>> def func():pass
>>> func(a.x=1)
File "<ipython-input-22-c75a0f520ac0>", line 1
SyntaxError: keyword can't be an expression使用liquorID__BottleSize代替。
相关:Why django has to use double underscore when making filter queries?
https://stackoverflow.com/questions/19783998
复制相似问题