django SyntaxError:关键字不能是表达式

RuS*_*uSs 5 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))
Run Code Online (Sandbox Code Playgroud)

ole*_*leg 5

您不能在参数名称中使用点号,因此这部分会liquorID.BottleSize='750 ML'导致SyntaxError

filter跨越关系的使用查找中使用相关模型

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

Django提供了一种强大而直观的方式来“跟踪”查找中的关系,并在幕后自动为您处理SQL JOIN。要跨越关系,只需在各个模型之间使用相关字段的字段名称,并用双下划线将其分开,直到找到所需的字段。

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

StoreLiquor.objects.filter(storeID=ID_Store, 
                           liquorID__BottleSize='750 ML',
                           custom=False).update(StorePrice=liquorID__ShelfPrice)
Run Code Online (Sandbox Code Playgroud)