# Path: cpm_generic/migration_utils.py
# def get_image_model(apps):
#     """ Return Image model that works in migrations.
# 
#     Models created by Django migration subsystem contain fields,
#     but dont' contain methods of the original models.
# 
#     The hack with adding method get_upload_to lets us save images in
#     migrations, e.g.:
#     >>> from django.core.files import File
#     >>> Image = get_image_model()
#     >>> photo = Image(title='example title')
#     >>> with open(path) as f:
#     ...     photo.file.save(name='name.png', content=File(f))
# 
#     Args:
#         apps (django.db.migrations.state.StateApps): Apps registry.
# 
#     Returns:
#         type: Image model.
#     """
#     from wagtail.wagtailimages.models import Image as LatestImage
# 
#     Image = apps.get_model('wagtailimages.Image')
#     Image.get_upload_to = LatestImage.get_upload_to.im_func
# 
#     return Image


from functools import partial
from django.core.files import File
from django.db import migrations
from cpm_generic.migration_utils import get_image_model
import json
import os

    collection_id = Collection.objects.filter(depth=1)[0]
    season = _get_season(apps, season_name)

    for item in sorted(_get_data(season_name), reverse=True):

        image = Image(title=item['name_en'], collection=collection_id)
        with open(_get_image_path(item['image']), 'rb') as image_file:
            image.file.save(name=item['image'], content=File(image_file))
            image.save()

        partner, _created = Partner.objects.get_or_create(
            name_en=item['name_en'],
            name_be=item['name_be'],
            name_ru=item['name_ru'],
            link=item['link'],
            image=image
        )

        SeasonRelatedPartner(season=season, partner=partner).save()


def remove_partners(apps, schema_editor, season_name):
    Partner = apps.get_model('cpm_data.Partner')
    SeasonRelatedPartner = apps.get_model('cpm_data.SeasonRelatedPartner')

    season = _get_season(apps, season_name)
    names = [item['name_en'] for item in _get_data(season_name)]
    partners = Partner.objects.filter(name_en__in=names)


# Path: cpm_generic/migration_utils.py
# def get_image_model(apps):
#     """ Return Image model that works in migrations.
# 
#     Models created by Django migration subsystem contain fields,
#     but dont' contain methods of the original models.
# 
#     The hack with adding method get_upload_to lets us save images in
#     migrations, e.g.:
#     >>> from django.core.files import File
#     >>> Image = get_image_model()
#     >>> photo = Image(title='example title')
#     >>> with open(path) as f:
#     ...     photo.file.save(name='name.png', content=File(f))
# 
#     Args:
#         apps (django.db.migrations.state.StateApps): Apps registry.
# 
#     Returns:
#         type: Image model.
#     """
#     from wagtail.wagtailimages.models import Image as LatestImage
# 
#     Image = apps.get_model('wagtailimages.Image')
#     Image.get_upload_to = LatestImage.get_upload_to.im_func
# 
#     return Image


# Path: cpm_data/migrations/0008_add_partners_data_2012_2013_2015.py
from functools import partial
from django.core.files import File
from django.db import migrations
from cpm_generic.migration_utils import get_image_model
import json
import os


    collection_id = Collection.objects.filter(depth=1)[0]
    season = _get_season(apps, season_name)

    for item in sorted(_get_data(season_name), reverse=True):

        image = Image(title=item['name_en'], collection=collection_id)
        with open(_get_image_path(item['image']), 'rb') as image_file:
            image.file.save(name=item['image'], content=File(image_file))
            image.save()

        partner, _created = Partner.objects.get_or_create(
            name_en=item['name_en'],
            name_be=item['name_be'],
            name_ru=item['name_ru'],
            link=item['link'],
            image=image
        )

        SeasonRelatedPartner(season=season, partner=partner).save()


def remove_partners(apps, schema_editor, season_name):
    Partner = apps.get_model('cpm_data.Partner')
    SeasonRelatedPartner = apps.get_model('cpm_data.SeasonRelatedPartner')

    season = _get_season(apps, season_name)
    names = [item['name_en'] for item in _get_data(season_name)]
    partners = Partner.objects.filter(name_en__in=names)


    SeasonRelatedPartner.objects.filter(