# -*- 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_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()

    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_pollsindexpage).delete()
        ct_question.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_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()


class Migration(migrations.Migration):
    dependencies = [
        ('tuneme', '0003_move_pages_to_index_pages'),
    ]

    operations = [
        migrations.RunPython(delete_polls_index_page),
    ]

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

Reorder migration and fix typo