SciPost Code Repository

Skip to content
Snippets Groups Projects
0010_repopulate_funder_orgs.py 755 B
Newer Older
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-09-22 13:11
from __future__ import unicode_literals

from django.db import migrations


def repopulate_organization_field(apps, schema_editor):
    Funder = apps.get_model('funders', 'Funder')
    Organization = apps.get_model('organizations', 'Organization')

Jorran de Wit's avatar
Jorran de Wit committed
    for funder in Funder.objects.filter(organization__isnull=False):
        funder.org = Organization.objects.get(name=funder.organization.name)
        funder.save()


class Migration(migrations.Migration):

    dependencies = [
        ('funders', '0009_funder_org'),
    ]

    operations = [
        migrations.RunPython(repopulate_organization_field,
                             reverse_code=migrations.RunPython.noop),
    ]