diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-21 15:45:46 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-21 15:45:46 +0200 |
commit | 36152b34e38cb39dda116ab4de4cd5360e66c6a8 (patch) | |
tree | 4feea20935fcf500b2ef52ab94433ccb319673b8 /ishtar_common | |
parent | 5957ad8979558c67a357a554201a1ecb4c428606 (diff) | |
download | Ishtar-36152b34e38cb39dda116ab4de4cd5360e66c6a8.tar.bz2 Ishtar-36152b34e38cb39dda116ab4de4cd5360e66c6a8.zip |
Add a script to fix external ids
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/management/commands/update_external_ids.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ishtar_common/management/commands/update_external_ids.py b/ishtar_common/management/commands/update_external_ids.py new file mode 100644 index 000000000..f69a865d7 --- /dev/null +++ b/ishtar_common/management/commands/update_external_ids.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys + +from django.core.management.base import BaseCommand + +from archaeological_operations.models import Parcel +from archaeological_context_records.models import ContextRecord +from archaeological_finds.models import BaseFind, Find + + +class Command(BaseCommand): + help = "./manage.py ishtar_execute_admin_tasks\n\n"\ + "Launch pending administration tasks." + + def handle(self, *args, **options): + for model in [Parcel, ContextRecord, BaseFind, Find]: + updated = 0 + print("* {}".format(model)) + total = model.objects.count() + for idx, item in enumerate(model.objects.all()): + sys.stdout.write("\r{}/{} ".format(idx, total)) + sys.stdout.flush() + updated += 1 if item.update_external_id(save=True) else 0 + print("\rupdated: {} ".format(updated)) |