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

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

概述我在以下代码行中遇到语法错误.我已导入数学,但我的更新功能仍无效.告诉我关键字不能是一个表达,并列举底部3行.知道我做错了什么吗? StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = liquorID.ShelfPrice)Sto 我在以下代码行中遇到语法错误.我已导入数学,但我的更新功能仍无效.告诉我关键字不能是一个表达,并列举底部3行.知道我做错了什么吗?

Storeliquor.objects.filter(storeID=ID_Store,liquorID.BottleSize='750 ML',custom=False).update(StorePrice = liquorID.ShelfPrice)Storeliquor.objects.filter(storeID=ID_Store,custom=False).update(StorePrice = (float(liquorID.OffPremisePrice)) + (float(S750Increase)))Storeliquor.objects.filter(storeID=ID_Store,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)
总结

以上是内存溢出为你收集整理的python – django语法错误:关键字不能是表达式全部内容,希望文章能够帮你解决python – django语法错误:关键字不能是表达式所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1192962.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存