import os from django.db import migrations from django.core.management import call_command def load_data(apps, __): OwnershipStatus = apps.get_model("archaeological_finds", "ownershipstatus") if not OwnershipStatus.objects.count(): migration = "0139_data_migration_ownership_status.json" json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1] + [migration]) call_command("loaddata", json_path) OwnerType = apps.get_model("archaeological_finds", "ownertype") if not OwnerType.objects.count(): migration = "0139_data_migration_owner_type.json" json_path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1] + [migration]) call_command("loaddata", json_path) class Migration(migrations.Migration): dependencies = [ ('archaeological_finds', '0138_donors_owner_ownership_status_collections'), ] operations = [ migrations.RunPython(load_data) ]