Shino
0
Q:

bulk create django

# took 0.47 seconds
def builtin():
    insert_list = []
    for i in range(10000):
        name="String number %s" %i
        insert_list.append(Record(name=name))
    Record.objects.bulk_create(insert_list)
2
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
1
Entry.objects.bulk_create([
  Entry(headline = "foo"),
  Entry(headline = "bar")
])
0

New to Communities?

Join the community