bulk_create(objs, batch_size = None, ignore_conflicts = False)
#eg
Entry.objects.bulk_create([
... Entry(headline='This is a test'),
... Entry(headline='This is only a test'),
... ])
# inserts in one query (usually), caveats below:
# doesn't signal pre_save and post_save
# cant use child models
# no many-to-many
# obj list fully evaluates if objs is a generator
objs = []
for person in p:
obj = People.objects.get(email=person['email'])
obj.birthday = person['birthday']
objs.append(obj)
People.objects.bulk_update(objs, ['birthday'], batch_size=1000)
from django.db import models
class Person(models.Model):
username = models.CharField(max_length = 200, unique = True)
firstName = models.CharField(max_length = 200)
middleName = models.CharField(max_length = 200)
lastName = models.CharField(max_length = 200)
age = models.IntegerField(default = 0)