[Answered ]-Group query results in batches of Python

1👍

total = Message.objects.all().count()
for i in xrange(0,total,500):
   batch = Message.objects.all()[i:500]

1👍

all_messages = Message.objects.all()

if all_messages.count() == 0:
    return

n = all_messages.count() / 500

for i in range (n if n else 1):
    messages = all_messages[i*500:(i+1)*500]
    bulk_send(messages)
👤Hardy

Leave a comment