From 34b4bd5dc5e07b8359bc7ed74c80f325cfed38e5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 29 Sep 2016 13:34:00 +0200 Subject: Operation: add a related name for towns - temp maintenance script for de-dup towns --- scripts/2016-09-29-clean-dup-towns-pdl.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 scripts/2016-09-29-clean-dup-towns-pdl.py (limited to 'scripts/2016-09-29-clean-dup-towns-pdl.py') diff --git a/scripts/2016-09-29-clean-dup-towns-pdl.py b/scripts/2016-09-29-clean-dup-towns-pdl.py new file mode 100644 index 000000000..e0fa1ffec --- /dev/null +++ b/scripts/2016-09-29-clean-dup-towns-pdl.py @@ -0,0 +1,23 @@ +from ishtar_common import Town + + +dup_nb = 0 +for dpt in ('44', '49', '53', '72', '85'): + for town in Town.objects.filter(numero_insee__ilike=dpt): + for dup in Town.objects.filter(name=town.name).exclude(pk=town.pk): + for item in dup.file_main.all(): + item.main_town = town + item.save() + for item in dup.parcels.all(): + item.main_town = town + item.save() + + for item in dup.file.all(): + item.towns.remove(dup) + item.towns.add(town) + for item in dup.operations.all(): + item.towns.remove(dup) + item.towns.add(town) + dup_nb += 1 + +print("{} items cleaned".format(dup_nb)) -- cgit v1.2.3