How to 'bulk update' with Django?

前端 未结 5 1063
挽巷
挽巷 2020-11-28 04:40

I\'d like to update a table with Django - something like this in raw SQL:

update tbl_name set name = \'foo\' where name = \'bar\'

My first

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 05:11

    IT returns number of objects are updated in table.

    update_counts = ModelClass.objects.filter(name='bar').update(name="foo")
    

    You can refer this link to get more information on bulk update and create. Bulk update and Create

提交回复
热议问题