如何转换为批量插入

How to convert to a Bulk Insert

给定以下数据,我将如何在 django 中执行 BulkInsert

list_of_data = [
    {'name': 'Paul'}, 
    {'name': 'Robert'
]

# with a normal insert
for data in list_of_data:
    Person.objects.create(name=data['name'])

使用bulk_create():

This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are)

Person.objects.bulk_create([Person(**data) for data in list_of_data])