diff options
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() |