summaryrefslogtreecommitdiff
path: root/ishtar_common/migrations/0093_auto_20190429_0950.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-29 11:12:07 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:27 +0200
commit2adf65aad9a99158da6eef7468dde7badd434b1e (patch)
tree239064507748fcde0dc8b1f6bdab7ebcbf2ed68e /ishtar_common/migrations/0093_auto_20190429_0950.py
parentaab04bcf162d1264f7612b729a0dfe3177f24d3f (diff)
downloadIshtar-2adf65aad9a99158da6eef7468dde7badd434b1e.tar.bz2
Ishtar-2adf65aad9a99158da6eef7468dde7badd434b1e.zip
Document templates: adapt models to manage labels
Diffstat (limited to 'ishtar_common/migrations/0093_auto_20190429_0950.py')
-rw-r--r--ishtar_common/migrations/0093_auto_20190429_0950.py50
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),
+ ]