Closed blokeish closed 4 months ago
from itertools import islice
from myapp.models import Entry
batch_size = 100
while True:
objs = (Entry(headline="Test %s" % i) for i in range(1000))
batch = list(islice(objs, batch_size))
if not batch:
break
Entry.objects.bulk_create(batch, batch_size)
try this
Make sure that the objs = (Entry(headline="Test %s" % i) for i in range(1000))
line is making a tuple rather than a list. If using a list it won't progress the iterator and will loop infinitely
This is the issue tracker for the djangoproject.com website. Please see TicketClosingReasons/UseSupportChannels for ways to get help with Django usage.
The code provide here seems to go into an infinite loop. The batch list variable seems to always get the first 100 items from objs list, so the batch list will never go empty.
I have seen this had got carried over to stack over flow. I am relatively new to Python and Django, so, sorry if I am making a stupid entry.