old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.11 on 2018-03-16 09:12
  from __future__ import unicode_literals
  
  from django.db import migrations, models
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('polls', '0050_auto_20170615_1455'),
      ]
  
      def populate_default_backend(apps, schema_editor):
          PollResult = apps.get_model("polls", "PollResult")
          PollResult.objects.all().update(backend='rapidpro')
  
      operations = [
          migrations.AddField(
              model_name='poll',
              name='backend',
              field=models.CharField(default='rapidpro', max_length=16),
          ),
          migrations.AddField(
              model_name='pollresult',
              name='backend',
              field=models.CharField(null=True, max_length=16),
          ),
          migrations.RunPython(populate_default_backend),
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.11 on 2018-03-16 09:12
  from __future__ import unicode_literals
  
  from django.db import migrations, models
  from ureport.utils import chunk_list
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('polls', '0050_auto_20170615_1455'),
      ]
  
      def populate_default_backend(apps, schema_editor):
          PollResult = apps.get_model("polls", "PollResult")
          result_ids = PollResult.objects.all().values_list('id', flat=True)
  
          start = time.time()
          i = 0
  
          for res_id_batch in chunk_list(result_ids, 1000):
              PollResult.objects.filter(id__in=res_id_batch).update(backend='rapidpro')
  
              i += len(res_id_batch)
  
              print "Processed poll results update %d in %ds" % (i, time.time() - start)
  
      operations = [
          migrations.AddField(
              model_name='poll',
              name='backend',
              field=models.CharField(default='rapidpro', max_length=16),
          ),
          migrations.AddField(
              model_name='pollresult',
              name='backend',
              field=models.CharField(null=True, max_length=16),
          ),
          migrations.RunPython(populate_default_backend),
      ]
  
subject: Update pull results default value in batches