I have what is essentially a table which is a pool of available 
codes/sequences for unique keys when I create records elsewhere in the DB.
Right now I run a transaction where I might grab 5000 codes out of an 
available pool of 1 billion codes using the slice operator [:code_count] 
where code_count == 5000.

This works fine, but then for every insert, I have to run through each code 
and insert it into the record manually when I use the code.

Is there a better way?

Example code (omitting other attributes for each new_item that are similar 
to all new_items):

code_count=5000
pool_cds = CodePool.objects.filter(free_indicator=True)[:code_count]


        for pool_cd in pool_cds:
            
            new_item = Item.objects.create(
                pool_cd = pool_cd.unique_code,
            )
            new_item.save()


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddb2de4d-d094-4512-9ad7-acd8bb33e627%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to