blob: e0fa1ffec55c11c090bdb2e68cff120531b71f66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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))
|