diff --git a/incident/migrations/0043_auto_20200306_1646.py b/incident/migrations/0043_auto_20200306_1646.py new file mode 100644 index 000000000..5f8f342a7 --- /dev/null +++ b/incident/migrations/0043_auto_20200306_1646.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2020-03-06 16:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('incident', '0042_copy_uncategorized_targets_to_gov_workers'), + ] + + operations = [ + migrations.AlterField( + model_name='incidentpage', + name='targeted_institutions', + field=models.ManyToManyField(blank=True, related_name='institutions_incidents', to='incident.Institution', verbose_name='Targeted Institutions'), + ), + ] diff --git a/incident/migrations/0044_copy_affiliation_to_institutions.py b/incident/migrations/0044_copy_affiliation_to_institutions.py new file mode 100644 index 000000000..fe9963345 --- /dev/null +++ b/incident/migrations/0044_copy_affiliation_to_institutions.py @@ -0,0 +1,39 @@ +# Generated by Django 2.2.10 on 2020-03-05 21:28 + +from django.db import migrations + + +def copy_affiliation(apps, schema_editor): + """Copy incident affiliations to """ + IncidentPage = apps.get_model('incident', 'IncidentPage') + Institution = apps.get_model('incident', 'Institution') + TargetedJournalist = apps.get_model('incident', 'TargetedJournalist') + + for incident in IncidentPage.objects.order_by('pk'): + if incident.affiliation and incident.affiliation != 'Independent': + inst, _ = Institution.objects.get_or_create(title=incident.affiliation) + + targeted_journos = incident.targeted_journalists.all() + if targeted_journos: + for tj in targeted_journos: + if not tj.institution: + tj.institution = inst + tj.save() + else: + incident.targeted_institutions.add(inst) + incident.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('incident', '0042_copy_uncategorized_targets_to_gov_workers'), + ] + + operations = [ + migrations.RunPython( + copy_affiliation, + reverse_code=migrations.RunPython.noop, + elidable=True, + ), + ] diff --git a/incident/migrations/0045_auto_20200306_1648.py b/incident/migrations/0045_auto_20200306_1648.py new file mode 100644 index 000000000..e171d854c --- /dev/null +++ b/incident/migrations/0045_auto_20200306_1648.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.10 on 2020-03-06 16:48 + +from django.db import migrations +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('incident', '0044_auto_20200306_1646'), + ] + + operations = [ + migrations.AlterField( + model_name='incidentpage', + name='targeted_institutions', + field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='institutions_incidents', to='incident.Institution', verbose_name='Targeted Institutions'), + ), + ]