diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-09-15 18:46:41 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-05 10:51:51 +0100 |
| commit | 3a6ebc8cda09035846cdb7a46af5bedc6b27d755 (patch) | |
| tree | ea86d84406cfee3d229ac77f385bbe9697158c1d /ishtar_common/migrations/0231_default_mandatory_keys.py | |
| parent | b02d86f02416edb7724db8145ae19c6d9a454c6e (diff) | |
| download | Ishtar-3a6ebc8cda09035846cdb7a46af5bedc6b27d755.tar.bz2 Ishtar-3a6ebc8cda09035846cdb7a46af5bedc6b27d755.zip | |
♻️ refactoring and optimisation: manage defaults like pre_importer_values - add an explicit field for required value to apply defaults
Diffstat (limited to 'ishtar_common/migrations/0231_default_mandatory_keys.py')
| -rw-r--r-- | ishtar_common/migrations/0231_default_mandatory_keys.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ishtar_common/migrations/0231_default_mandatory_keys.py b/ishtar_common/migrations/0231_default_mandatory_keys.py new file mode 100644 index 000000000..4c5e2ea35 --- /dev/null +++ b/ishtar_common/migrations/0231_default_mandatory_keys.py @@ -0,0 +1,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_20230918_1655'), + ] + + operations = [ + migrations.RunPython(migrate), + ] |
