

def migrate_tags(apps, schema_editor):
    LatestPostsPlugin = apps.get_model('djangocms_blog', 'LatestPostsPlugin')
    Tag = apps.get_model('taggit', 'Tag')
    TaggedItem = apps.get_model('taggit', 'TaggedItem')
    plugin_content_type = ContentType.objects.get_for_model(LatestPostsPlugin)
    for tag in Tag.objects.all():
        for plugin in tag.latestpostsplugin_set.all():
            if (not TaggedItem.objects.filter(tag=tag, object_id=plugin.pk, content_type_id=plugin_content_type.pk).exists()):
                TaggedItem.objects.create(tag=tag, object_id=plugin.pk, content_type_id=plugin_content_type.pk)

dataset/ETHPy150Open nephila/djangocms-blog/djangocms_blog/migrations/0009_latestpostsplugin_tags_new.py migrate_tags/original