diff options
Diffstat (limited to 'ishtar_common/migrations/0093_auto_20190429_0950.py')
-rw-r--r-- | ishtar_common/migrations/0093_auto_20190429_0950.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ishtar_common/migrations/0093_auto_20190429_0950.py b/ishtar_common/migrations/0093_auto_20190429_0950.py new file mode 100644 index 000000000..d2bc6a395 --- /dev/null +++ b/ishtar_common/migrations/0093_auto_20190429_0950.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-04-29 09:50 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +CLASS_NAMES = { + 'archaeological_operations.models.AdministrativeAct': "Acte administratif" +} + + +def migrate_to_model_fk(apps, schema_editor): + ImporterModel = apps.get_model('ishtar_common', 'ImporterModel') + DocumentTemplate = apps.get_model('ishtar_common', 'DocumentTemplate') + importer_models = {} + for doc in DocumentTemplate.objects.all(): + if doc.associated_object_name not in importer_models: + if doc.associated_object_name in CLASS_NAMES: + name = CLASS_NAMES[doc.associated_object_name] + else: + name = "-" + importer_models[doc.associated_object_name], __ = \ + ImporterModel.objects.get_or_create( + klass=doc.associated_object_name, + defaults={"name": name} + ) + doc.associated_model = importer_models[doc.associated_object_name] + doc.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0092_ishtarsiteprofile_display_srs'), + ] + + operations = [ + migrations.AlterModelOptions( + name='importermodel', + options={'ordering': ('name',), 'verbose_name': 'Model', 'verbose_name_plural': 'Models'}, + ), + migrations.AddField( + model_name='documenttemplate', + name='associated_model', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.ImporterModel'), + ), + migrations.RunPython(migrate_to_model_fk), + ] |