1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# -*- 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
from django.utils.text import slugify
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}
)
if not doc.slug:
doc.slug = slugify(doc.name)
doc.associated_model = importer_models[doc.associated_object_name]
doc.save()
class Migration(migrations.Migration):
dependencies = [
('ishtar_common', '0093_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),
]
|