old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.9.13 on 2017-09-13 10:30
  from __future__ import unicode_literals
  
  from django.db import migrations
  
  
  def delete_polls_index_page(apps, schema_editor):
      Page = apps.get_model("wagtailcore", "Page")
      ContentType = apps.get_model('contenttypes.ContentType')
      db_alias = schema_editor.connection.alias
  
      ct_choice = ContentType.objects.using(db_alias).filter(
          model="choice", app_label="polls").first()
      if ct_choice:
          Page.objects.using(db_alias).filter(content_type=ct_choice).delete()
          ct_choice.delete()
  
      ct_freetextquestion = ContentType.objects.using(db_alias).filter(
          model="freetextquestion", app_label="polls").first()
      if ct_freetextquestion:
          Page.objects.using(db_alias).filter(
              content_type=ct_freetextquestion).delete()
          ct_freetextquestion.delete()
  
      ct_question = ContentType.objects.using(db_alias).filter(
          model="question", app_label="polls").first()
      if ct_question:
          Page.objects.using(db_alias).filter(
              content_type=ct_question).delete()
          ct_question.delete()
  
      ct_pollsindexpage = ContentType.objects.using(db_alias).filter(
          model="pollsindexpage", app_label="polls").first()
      if ct_pollsindexpage:
          Page.objects.using(db_alias).filter(
              content_type=ct_pollsindexpage).delete()
          ct_pollsindexpage.delete()
  
  
  class Migration(migrations.Migration):
      dependencies = [
          ('tuneme', '0003_move_pages_to_index_pages'),
      ]
  
      operations = [
          migrations.RunPython(delete_polls_index_page),
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.9.13 on 2017-09-13 10:30
  from __future__ import unicode_literals
  
  from django.db import migrations
  
  
  def delete_polls_index_page(apps, schema_editor):
      Page = apps.get_model("wagtailcore", "Page")
      ContentType = apps.get_model('contenttypes.ContentType')
      db_alias = schema_editor.connection.alias
  
      ct_choice = ContentType.objects.using(db_alias).filter(
          model="choice", app_label="polls").first()
      if ct_choice:
          Page.objects.using(db_alias).filter(content_type=ct_choice).delete()
          ct_choice.delete()
  
      ct_freetextquestion = ContentType.objects.using(db_alias).filter(
          model="freetextquestion", app_label="polls").first()
      if ct_freetextquestion:
          Page.objects.using(db_alias).filter(
              content_type=ct_freetextquestion).delete()
          ct_freetextquestion.delete()
  
      ct_question = ContentType.objects.using(db_alias).filter(
          model="question", app_label="polls").first()
      if ct_question:
          Page.objects.using(db_alias).filter(
              content_type=ct_question).delete()
          ct_question.delete()
  
      ct_pollsindexpage = ContentType.objects.using(db_alias).filter(
          model="pollsindexpage", app_label="polls").first()
      if ct_pollsindexpage:
          Page.objects.using(db_alias).filter(
              content_type=ct_pollsindexpage).delete()
          ct_pollsindexpage.delete()
  
  
  class Migration(migrations.Migration):
      dependencies = [
          ('tuneme', '0003_move_pages_to_index_pages'),
      ]
  
      operations = [
          migrations.RunSQL("DELETE FROM polls_choicevote;"),
          migrations.RunSQL("DELETE FROM polls_freetextvote;"),
          migrations.RunSQL("DELETE FROM polls_choice;"),
          migrations.RunSQL("DELETE FROM polls_freetextquestion;"),
          migrations.RunSQL("DELETE FROM polls_question;"),
          migrations.RunSQL("DELETE FROM polls_pollsindexpage;"),
          migrations.RunPython(delete_polls_index_page),
      ]
  
subject: clear old polls table before deleting page models