Django update table using data from another table

前端 未结 3 1100
庸人自扰
庸人自扰 2020-12-15 05:18

I have 2 tables products and catagories connected by foreign key. I need to update field products.new_cost using field catagorie

3条回答
  •  执念已碎
    2020-12-15 05:37

    rows = Product.objects.filter(old_field__isnull=False)
    for row in rows:
         row.new_field = row.old_field.subfield
    Product.objects.bulk_update(rows, ['new_field'])
    

提交回复
热议问题