From f2133b1363d3d275ce063c0cddebb3fb862e2637 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 8 Jul 2024 14:09:48 +0200 Subject: ✨ Context records - identification: switch to multivalued MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0117_identification_m2m.py | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 archaeological_context_records/migrations/0117_identification_m2m.py (limited to 'archaeological_context_records/migrations') diff --git a/archaeological_context_records/migrations/0117_identification_m2m.py b/archaeological_context_records/migrations/0117_identification_m2m.py new file mode 100644 index 000000000..0e91aa3e6 --- /dev/null +++ b/archaeological_context_records/migrations/0117_identification_m2m.py @@ -0,0 +1,52 @@ +# Generated by Django 2.2.24 on 2024-07-08 13:30 + +from django.db import migrations, models + + +def m2m_identification_type(apps, __): + ContextRecord = apps.get_model("archaeological_context_records", "contextrecord") + for cr in ContextRecord.objects.filter(identification__isnull=False).all(): + cr.identifications.add(cr.identification) + + +SQL1 = """ +UPDATE ishtar_common_importtarget + SET target='identifications' +WHERE target='identification'; +""" + +SQL2 = """ +UPDATE ishtar_common_formatertype + SET many_split='&' +WHERE options='archaeological_context_records.models.IdentificationType'; +""" + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_context_records', '0116_recordrelations_import_relationship'), + ] + + operations = [ + migrations.AlterModelOptions( + name='activitytype', + options={'ordering': ('order', 'label'), 'verbose_name': 'Activity Type', 'verbose_name_plural': 'Activity Types'}, + ), + migrations.AddField( + model_name='contextrecord', + name='identifications', + field=models.ManyToManyField(blank=True, related_name='context_records', to='archaeological_context_records.IdentificationType', verbose_name='Identification'), + ), + migrations.RunPython(m2m_identification_type), + migrations.RemoveField( + model_name='contextrecord', + name='identification', + ), + migrations.RemoveField( + model_name='historicalcontextrecord', + name='identification', + ), + migrations.RunSQL(SQL1), + migrations.RunSQL(SQL2), + ] -- cgit v1.2.3