The following should do:
Item.objects.bulk_create([
Item(pool_cd=pool_cd.unique_code)
for pool_cd in pool_cds
])
Le jeudi 4 septembre 2014 12:44:08 UTC-4, James P a écrit :
>
> I forgot to include the code where I set the pool codes to NOTFREE, here
> is the whole snippet.
>
>
I believe it does, all you do is provide a list of lazily populated models (as
if you were going to create them one by one) and give it to bulk_create. This
SO post has a pretty good write up in the accepted answer, along with a few
other options that may save you some time:
The issue is that a bulk create doesn't allow me to use my unique values
for each create which I need from the code pool. Does it?
On Thursday, September 4, 2014 10:42:52 AM UTC-6, James Schneider wrote:
>
> You probably want to look at bulk_create and do all of the inserts as a
> single query:
I forgot to include the code where I set the pool codes to NOTFREE, here is
the whole snippet.
code_count=5000
pool_cds = CodePool.objects.filter(free_indicator=True)[:code_count]
for pool_cd in pool_cds:
new_item = Item.objects.create(
You probably want to look at bulk_create and do all of the inserts as a
single query:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create
This will probably be seconds, if not minutes faster.
-James
On Thursday, September 4, 2014, James P wrote:
> I
5 matches
Mail list logo