I think this is the method you are looking for: https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create
The code is copied from the documentation:
Entry.objects.bulk_create([ Entry(headline='This is a test'), Entry(headline='This is only a test'), ])
Which in practice will look like this:
my_entries = list() for i in range(100): my_entries.append(Entry(headline='Headline #'+str(i)) Entry.objects.bulk_create(my_entries)
According to the docs, this performs one query, regardless of the size of the list (maximum 999 elements in SQLite3), which cannot be said of the atomic decorator.
There is an important distinction to be made. On the OP question, it sounds like he's trying to create mass creation, not mass conservation. atomic decorator is the fastest solution to save, but not to create.
source share