在 Django 中:如何将两列相乘并保存到更新查询中的另一列?
class A(models.Model):
revenue = models.FloatField()
list_price = models.FloatField()
unit_sold = models.FloatField()
我有这个模型,list_price 和unit_sold 有 1M 条记录 我想使用 list_price * unit_sold 填充收入列
class A(models.Model):
revenue = models.FloatField()
list_price = models.FloatField()
unit_sold = models.FloatField()
I have this model which has 1M records in list_price and unit_sold
I want to fill revenue column using list_price * unit_sold
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在覆盖表单中的
save
函数时,请在 save 之前添加result = list_price * unit_sold
。In overwrite your
save
function in the form, addresult = list_price * unit_sold
before save.