diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-05-12 15:40:46 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:00 +0100 |
commit | c0b5c70f34fe0df39da08818a8649c1f0125e905 (patch) | |
tree | 72841baefc2f7874b6819c603b7e0fba1e6fc3dd /archaeological_context_records | |
parent | 12de821ded4f964c89d1ac758701bcaf4750e7de (diff) | |
download | Ishtar-c0b5c70f34fe0df39da08818a8649c1f0125e905.tar.bz2 Ishtar-c0b5c70f34fe0df39da08818a8649c1f0125e905.zip |
Geodata: improve migrate script (multi processing) - fix upper model
Diffstat (limited to 'archaeological_context_records')
-rw-r--r-- | archaeological_context_records/models.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 3a89a6ca9..e279c55fa 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -398,6 +398,8 @@ class CRBulkView(object): class GeographicSubTownItem(GeoItem): + UPPER_GEO = [] + class Meta: abstract = True @@ -433,19 +435,34 @@ class GeographicSubTownItem(GeoItem): self.main_geodata = None modified = True + for upper_attr in self.UPPER_GEO: + upper = getattr(self, upper_attr, None) + if upper and upper.main_geodata and \ + upper.main_geodata_id not in self.geodata.values_list( + "id", flat=True): + modified = True + self.geodata.add(upper.main_geodata) + if not self.main_geodata: + self.main_geodata = upper.main_geodata + if not has_geo_town: - if modified and save: - self.skip_history_when_saving = True - self._no_move = True - self.save() + if modified: + if save: + self.skip_history_when_saving = True + self._no_move = True + self.save() + else: + return True return if not q_geodata_current_town.filter(source_id=town.id).count(): self.geodata.add(town.main_geodata) - if save: - self.skip_history_when_saving = True - self._no_move = True - self.save() + if save: + self.skip_history_when_saving = True + self._no_move = True + self.save() + else: + return True class ContextRecord( @@ -671,6 +688,7 @@ class ContextRecord( "short_label", "town_label_with_areas", ] + UPPER_GEO = ["operation", "archaeological_site"] history = HistoricalRecords(bases=[HistoryModel]) objects = UUIDModelManager() |