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

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

上一篇:Oracle 使用本地IP地址连接异常的解决方法


下一篇:ubuntu下安装mysql