diff options
-rw-r--r-- | archaeological_warehouse/models.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 8c9a94f06..54fc09769 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -2027,9 +2027,28 @@ class Container( q.update(cached_division="") return ((self.__class__, q.values_list("id", flat=True)),) + def _update_childs_divisions(self): + q = Container.objects.filter(parent_id=self.id) + for child in q.all(): + cached_division = child._generate_cached_division() + cached_label = child._generate_cached_label() + cached_weight = child._generate_cached_weight() + Container.objects.filter(pk=child.pk).update( + cached_division=cached_division, + cached_label=cached_label, + cached_weight=cached_weight + ) + print("Yololo") + child._update_childs_divisions() + """ + find.... update with history writing.... + """ + def save(self, *args, **kwargs): + self._cached_location, self._cached_parent = None, None if self.pk: logger.debug(f"[ishtar] archaeological_warehouse.models.Container.save - {self.pk} - {self.cached_label}") + self._cached_location, self._cached_parent = Container.objects.filter(pk=self.pk).values_list("location_id", "parent_id").all()[0] self.pre_save() super().save(*args, **kwargs) self.update_find_location() @@ -2040,6 +2059,10 @@ class Container( updated += self._calculate_weight() + # update cached_label for childs + if self._cached_location != self.location_id or self._cached_parent != self.parent_id: + self._update_childs_divisions() + if not self.index and not self.container_type.stationary: self.skip_history_when_saving = True q = ( |