Re: Best way to batch select unique ids out of pool for sequences

2014-09-04 Thread Simon Charette
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. > >

RE: Best way to batch select unique ids out of pool for sequences

2014-09-04 Thread James Schneider
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:

Re: Best way to batch select unique ids out of pool for sequences

2014-09-04 Thread James P
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:

Re: Best way to batch select unique ids out of pool for sequences

2014-09-04 Thread James P
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(

Re: Best way to batch select unique ids out of pool for sequences

2014-09-04 Thread James Schneider
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