我有一个calculation = models.FloatField(default=0)
字段,我正试图将新值(根据Debugger its 32)分配给它,如下所示:
def calculate(**kwargs):
row = ContractorScoring.objects.select_related('client', 'lead', 'budgetOptions', 'techCompatibility',
'availableMen', 'degreeOfElaboration', 'geography',
'nonInHouseReady', 'existingItPartner', 'httpsAvailability',
'monthlyAdsBudget', 'mobilePageLoadSpeed', 'desktopPageLoadSpeed',
'organicTraficTrend', 'payedTraficTrend', 'techStackEquality',
'projectType', 'customerReadiness', 'servicesMeet')
points_sum = float(row[0].budgetOptions.points + row[0].techCompatibility.points +
row[0].availableMen.points + row[0].degreeOfElaboration.points +
row[0].geography.points + row[0].nonInHouseReady.points +
row[0].existingItPartner.points + row[0].httpsAvailability.points +
row[0].monthlyAdsBudget.points + row[0].mobilePageLoadSpeed.points +
row[0].desktopPageLoadSpeed.points + row[0].organicTraficTrend.points +
row[0].payedTraficTrend.points + row[0].techStackEquality.points +
row[0].projectType.points + row[0].customerReadiness.points + row[0].servicesMeet.points)
row[0].calculation = points_sum
print(str(row[0].calculation))
row[0].save(update_fields=['calculation'])
return row[0].calculation
当我打印row[0].calculation
值时,它会给我默认值0,0
你知道我做错了什么吗
您不应该修改仍在查询集中的模型实例(
row[0]
,其中row
有点用词不当)而是抓住对象本身:
请注意,您在
ContractorScoring
查询中缺少任何类型的过滤器,因此根本无法保证您将获得各种ContractorCoring的哪个对象!那可能不是你想要的相关问题 更多 >
编程相关推荐