Django bulk_create a list of lists
<p>As the title indicates, is there a way to bulk_create list of lists. Like right now I bulk_create it like - </p>

<pre><code>for i in range(len(x))   
  arr1 = []
    for m in range(len(y)):
    arr1.append(DataModel(foundation=foundation, date=dates[m], price=price[m]))
  DataModel.objects.bulk_create(arr1)
</code></pre>

<p>Now this will bulk create till the length of x.</p>

<p>Can it be done like so -</p>

<pre><code>arr = []
for i in range(len(x))   
  arr1 = []
    for m in range(len(y)):
    arr1.append(DataModel(foundation=foundation, date=dates[m], price=price[m]))
  arr.append(arr1)
DataModel.objects.bulk_create(arr)
</code></pre>

<p>If not, what else can be done to store data faster?</p>

<p>Try this....</p>

<pre><code>arr = []
for i in range(len(x))   
  arr1 = []
    for m in range(len(y)):
    arr1.append(DataModel(foundation=foundation, date=dates[m], price=price[m]))
  #instead of appending the list, add list together to make one
  arr = arr + arr1
DataModel.objects.bulk_create(arr)
</code></pre>

<p>this will produce a single list of items process-able by <code>bulk_create()</code> method</p>

<p>reference: <a href="http://stackoverflow.com/questions/2022031/python-append-vs-operator-on-lists-why-do-these-give-different-results">Python append() vs. + operator on lists, why do these give different results?</a></p>

python django