summaryrefslogtreecommitdiff
path: root/ishtar_common/migrations/0231_default_mandatory_keys.py
blob: 59624d00b1d0bed80540afa55374cb25a8093743 (plain)
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
# Generated by Django 2.2.24 on 2023-09-18 17:05

from django.db import migrations

EXCLUDE_LIST = [
    "-",
    "auto_external_id",
    "spatial_reference_system",
    "public_domain",
]

FULL_COPY_LIST = [
    "scientist__attached_to",
]


def migrate(apps, __):
    ImporterDefault = apps.get_model('ishtar_common', 'ImporterDefault')
    for default in ImporterDefault.objects.all():
        if default.target not in EXCLUDE_LIST:
            req = default.target
            if req not in FULL_COPY_LIST:
                req = req.split("__")[0]
            if req.endswith("_type") or req.endswith("_types"):
                continue
            default.required_fields = req
            default.save()


class Migration(migrations.Migration):

    dependencies = [
        ('ishtar_common', '0230_auto_20231005_1650'),
    ]

    operations = [
        migrations.RunPython(migrate),
    ]