From ff317a39a65ccd2c919ece5f0923d04712f4a3c4 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 11 Jun 2020 10:28:04 +0200 Subject: Container: change child location on location change (refs #4938) --- archaeological_warehouse/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'archaeological_warehouse/models.py') diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index a901b48c9..e130671a3 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -813,6 +813,14 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, def _get_base_image_path(self): return self.location._get_base_image_path() + "/" + self.external_id + @classmethod + def _change_parent_location(cls, parent): + for child in cls.objects.filter(parent=parent).all(): + if child.location != parent.location: + child.location = parent.location + child.save() + cls._change_parent_location(child) + def merge(self, item, keep_old=False, exclude_fields=None): # merge child containers child_references = {} @@ -829,6 +837,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, else: child.parent = self child.save() + self._change_parent_location(self) super(Container, self).merge(item, keep_old=keep_old, exclude_fields=exclude_fields) @@ -1126,6 +1135,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, def save(self, *args, **kwargs): self.pre_save() super(Container, self).save(*args, **kwargs) + self._change_parent_location(self) updated = False if not self.index: -- cgit v1.2.3