diff --git a/management/commands/_import_utils.py b/management/commands/_import_utils.py index d9243a3..9563517 100644 --- a/management/commands/_import_utils.py +++ b/management/commands/_import_utils.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import json + from django.core.management.base import BaseCommand from collections import defaultdict from django.apps import apps @@ -15,6 +17,10 @@ class ImportCommand(BaseCommand): Generic command for import of NK15 database """ + def __init__(self, *args, **kwargs): + super().__init__(args, kwargs) + self.MAP_IDBDE = dict() + def print_success(self, to_print): return self.stdout.write(self.style.SUCCESS(to_print)) @@ -36,6 +42,14 @@ class ImportCommand(BaseCommand): parser.add_argument('-c', '--chunk', type=int, default=100, help="chunk size for bulk_create") return parser + def save_map(self, filename): + with open(filename, 'w') as fp: + json.dump(self.MAP_IDBDE, fp, sort_keys=True, indent=2) + + def load_map(self, filename): + with open(filename, 'w') as fp: + self.MAP_IDBDE = json.load(fp) + class BulkCreateManager(object): """