bulk get or create django code example
Example 1: bulk create django
bulk_create(objs, batch_size = None, ignore_conflicts = False)
Entry.objects.bulk_create([
... Entry(headline='This is a test'),
... Entry(headline='This is only a test'),
... ])
Example 2: django bulk update
objs = [
Entry.objects.create(headline='Entry 1'),
Entry.objects.create(headline='Entry 2'),
]
objs[0].headline = 'This is entry 1'
objs[1].headline = 'This is entry 2'
Entry.objects.bulk_update(objs, ['headline'])
Example 3: django bulk update
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)