old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.10.6 on 2017-04-06 17:33
  from __future__ import unicode_literals
  
  from django.db import migrations
  from temba.utils import chunk_list
  
  
  def do_populate_send_all(Broadcast):
      broadcast_ids = Broadcast.objects.all().values_list('id', flat=True)
  
      for chunk in chunk_list(broadcast_ids, 1000):
          Broadcast.objects.filter(pk__in=chunk).update(send_all=False)
  
  
  def apply_as_migration(apps, schema_editor):
      Broadcast = apps.get_model('msgs', 'Broadcast')
      do_populate_send_all(Broadcast)
  
  
  def apply_manual():
      from temba.msgs.models import Broadcast
      do_populate_send_all(Broadcast)
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('msgs', '0086_broadcast_send_all'),
      ]
  
      operations = [
          migrations.RunPython(apply_as_migration)
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.10.6 on 2017-04-06 17:33
  from __future__ import unicode_literals
  
  from django.db import migrations
  from temba.utils import chunk_list
  
  
  def do_populate_send_all(Broadcast):
      broadcast_ids = Broadcast.objects.all().values_list('id', flat=True)
  
      broadcast_count = len(broadcast_ids)
      print('Starting to update %d broadcasts send all field...' % broadcast_count)
  
      updated = 0
      for chunk in chunk_list(broadcast_ids, 1000):
          Broadcast.objects.filter(pk__in=chunk).update(send_all=False)
          print("Updated %d of %d broadcasts" % (updated + len(chunk), broadcast_count))
  
  
  def apply_as_migration(apps, schema_editor):
      Broadcast = apps.get_model('msgs', 'Broadcast')
      do_populate_send_all(Broadcast)
  
  
  def apply_manual():
      from temba.msgs.models import Broadcast
      do_populate_send_all(Broadcast)
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('msgs', '0086_broadcast_send_all'),
      ]
  
      operations = [
          migrations.RunPython(apply_as_migration)
      ]
  
subject: Print progress of data migration