diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-06-29 15:37:18 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8 (patch) | |
tree | d915605d6207355788d69ad9a8e2a3a35d94507d /archaeological_warehouse/models.py | |
parent | 1d6484bfe6bbdf763f6a9c583115c1c6b3914037 (diff) | |
download | Ishtar-a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8.tar.bz2 Ishtar-a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8.zip |
Container - bulk update: remove parent when changing warehouse (refs #4959)
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r-- | archaeological_warehouse/models.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 565b64af2..04936d7a5 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -821,12 +821,12 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, return self.location._get_base_image_path() + "/" + self.external_id @classmethod - def _change_parent_location(cls, parent): + def _change_child_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) + cls._change_child_location(child) def merge(self, item, keep_old=False, exclude_fields=None): # merge child containers @@ -844,7 +844,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, else: child.parent = self child.save() - self._change_parent_location(self) + self._change_child_location(self) super(Container, self).merge(item, keep_old=keep_old, exclude_fields=exclude_fields) @@ -980,7 +980,8 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, return # modify existing - current_localisations = self.get_localisations() + ## first localisation is the warehouse + current_localisations = list(self.get_localisations())[1:] current_localisation, current_parent = None, None for loca in current_localisations: if loca.container_type == current_container_type: @@ -1143,7 +1144,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) + self._change_child_location(self) updated = False if not self.index: |