首页 > 其他 > 详细

django 大量数据批量修改 django-bulk-update

时间:2021-07-23 11:11:55      阅读:75      评论:0      收藏:0      [点我收藏+]

django-bulk-update
https://github.com/aykut/django-bulk-update
效果非常好,django3.1起支持批量数据库修改
但项目用的是django 1.11.8 只能使用第三方库

import random
from django_bulk_update.helper import bulk_update
from tests.models import Person

random_names = [‘Walter‘, ‘The Dude‘, ‘Donny‘, ‘Jesus‘]
people = Person.objects.all()
for person in people:
  person.name = random.choice(random_names)

bulk_update(people, update_fields=[‘name‘])  # updates only name column
bulk_update(people, exclude_fields=[‘username‘])  # updates all columns except username
bulk_update(people, using=‘someotherdb‘)  # updates all columns using the given db
bulk_update(people)  # updates all columns using the default db
bulk_update(people, batch_size=50000)  # updates all columns by 50000 sized chunks using the default db

django 大量数据批量修改 django-bulk-update

原文:https://www.cnblogs.com/mktom/p/15047006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!