# -*- 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)
    ]

Add data migrations to populate broadcast send all field
Add data migrations to populate broadcast send all field
