diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-29 13:34:00 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-29 13:34:00 +0200 |
commit | 3e5348bd79ae3575710a8aa9b58589754665d917 (patch) | |
tree | 87f210b8cddd5e68a0bafa68d48db264403902d5 | |
parent | 4eff275ae272752b91f1c87b2085689923bb1366 (diff) | |
download | Ishtar-3e5348bd79ae3575710a8aa9b58589754665d917.tar.bz2 Ishtar-3e5348bd79ae3575710a8aa9b58589754665d917.zip |
Operation: add a related name for towns - temp maintenance script for de-dup towns
-rw-r--r-- | archaeological_operations/models.py | 3 | ||||
-rw-r--r-- | scripts/2016-09-29-clean-dup-towns-pdl.py | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 926e27b3b..0cebcf292 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -212,7 +212,8 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, surface = models.IntegerField(_(u"Surface (m2)"), blank=True, null=True) remains = models.ManyToManyField("RemainType", verbose_name=_(u'Remains'), null=True, blank=True) - towns = models.ManyToManyField(Town, verbose_name=_(u"Towns")) + towns = models.ManyToManyField(Town, verbose_name=_(u"Towns"), + related_name='operations') cost = models.IntegerField(_(u"Cost (euros)"), blank=True, null=True) # preventive periods = models.ManyToManyField(Period, verbose_name=_(u"Periods"), 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)) |