summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py10
1 files changed, 10 insertions, 0 deletions
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: