diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-06-11 10:28:04 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 | 
| commit | ff317a39a65ccd2c919ece5f0923d04712f4a3c4 (patch) | |
| tree | 4cf17ffe4fa7e6bc4c184327034171501ccb3713 /archaeological_warehouse/models.py | |
| parent | 0b211ec1ff9a3f81b4a642acccd27c4480ab38c4 (diff) | |
| download | Ishtar-ff317a39a65ccd2c919ece5f0923d04712f4a3c4.tar.bz2 Ishtar-ff317a39a65ccd2c919ece5f0923d04712f4a3c4.zip | |
Container: change child location on location change (refs #4938)
Diffstat (limited to 'archaeological_warehouse/models.py')
| -rw-r--r-- | archaeological_warehouse/models.py | 10 | 
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: | 
