Skip to content

Instantly share code, notes, and snippets.

@yakky
Last active June 25, 2016 14:05
Show Gist options
  • Save yakky/b86817691997b1817e76384cbeb3617f to your computer and use it in GitHub Desktop.
Save yakky/b86817691997b1817e76384cbeb3617f to your computer and use it in GitHub Desktop.
Migrate to filer ThumbnailOption
  1. Add the discovery of proper ThumbnailOption model in you app models.py
  2. Create a manual migration like in example_migration.py
  3. In every migration (even existing ones) add:

    from custom_plugins.models import thumbnail_model
  4. In every migration (even existing ones) replace 'cmsplugin_filer_image.ThumbnailOption' with thumbnail_model like here https://github.com/nephila/djangocms-blog/blob/develop/djangocms_blog/migrations/0001_initial.py#L12 -> https://github.com/nephila/djangocms-blog/blob/develop/djangocms_blog/migrations/0001_initial.py#L108
# -*- coding: utf-8 -*-
# This migration must be created manually
from __future__ import unicode_literals
from django.db import migrations, models
from custom_plugins.models import thumbnail_model
class Migration(migrations.Migration):
if 'cmsplugin_filer' not in thumbnail_model:
dependencies = [
('custom_plugins', 'PREVIOUS_MIGRATION'),
('filer', '0003_thumbnailoption'),
('cmsplugin_filer_image', '0003_mv_thumbnail_option_to_filer_20160119_1720'),
]
run_before = [
('cmsplugin_filer_image', '0004_auto_20160120_0950'),
]
else:
dependencies = [
('filer', '__first__'),
('cmsplugin_filer_image', '__first__'),
('custom_plugins', 'PREVIOUS_MIGRATION'),
]
operations = [
migrations.AlterField(
model_name='MyModel', ## Add your model name
name='ThumbnailOptionField', ## Add your field name
field=models.ForeignKey(related_name='MyRelatedName',
verbose_name='Main image full', blank=True,
to=thumbnail_model, null=True),
),
...
]
# -*- coding: utf-8 -*-
import foo
...
try:
from cmsplugin_filer_image.models import ThumbnailOption # NOQA
except ImportError:
from filer.models import ThumbnailOption # NOQA
thumbnail_model = '%s.%s' % (
ThumbnailOption._meta.app_label, ThumbnailOption.__name__
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment