# Path: cpm_generic/migration_utils.py
# def remove_subpage(parent, model, **kwargs):
#     parent.numchild -= 1
# 
#     model.objects.filter(**kwargs).delete()
#     parent.save()


from django.db import migrations
from cpm_generic.migration_utils import remove_subpage
# -*- coding: utf-8 -*-
from __future__ import unicode_literals




def clear_jury_data(apps, schema_editor):
    HomePage = apps.get_model('home.HomePage')
    IndexPage = apps.get_model('cpm_generic.IndexPage')
    JuryMemberPage = apps.get_model('results.JuryMemberPage')
    RelatedJuryMember = apps.get_model('results.ResultsRelatedJuryMember')

    homepage = HomePage.objects.get(slug='home')
    juryindex = IndexPage.objects.get(slug='jury')

    for obj in RelatedJuryMember.objects.all():
        obj.delete()

    for obj in JuryMemberPage.objects.all():
        obj.photo.delete()
        remove_subpage(
            parent=juryindex,
            model=JuryMemberPage,
            id=obj.id
        )


# Path: cpm_generic/migration_utils.py
# def remove_subpage(parent, model, **kwargs):
#     parent.numchild -= 1
# 
#     model.objects.filter(**kwargs).delete()
#     parent.save()


# Path: results/migrations/0020_clear_jurymemberpage.py
from django.db import migrations
from cpm_generic.migration_utils import remove_subpage

# -*- coding: utf-8 -*-
from __future__ import unicode_literals




def clear_jury_data(apps, schema_editor):
    HomePage = apps.get_model('home.HomePage')
    IndexPage = apps.get_model('cpm_generic.IndexPage')
    JuryMemberPage = apps.get_model('results.JuryMemberPage')
    RelatedJuryMember = apps.get_model('results.ResultsRelatedJuryMember')

    homepage = HomePage.objects.get(slug='home')
    juryindex = IndexPage.objects.get(slug='jury')

    for obj in RelatedJuryMember.objects.all():
        obj.delete()

    for obj in JuryMemberPage.objects.all():
        obj.photo.delete()
        remove_subpage(
            parent=juryindex,
            model=JuryMemberPage,
            id=obj.id
        )


    remove_subpage(