summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-11-04 18:15:25 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-11-04 18:15:45 +0100
commitad4981972fcab73e4dadd5ba4a2965b8c1c3ad2c (patch)
tree50e119ad050f4712e005ade8c48b5959fe18b0b9 /ishtar_common/models_common.py
parentbf9ed50639b4e7a509050763de1fe9f9878dcfdd (diff)
downloadIshtar-ad4981972fcab73e4dadd5ba4a2965b8c1c3ad2c.tar.bz2
Ishtar-ad4981972fcab73e4dadd5ba4a2965b8c1c3ad2c.zip
🚧 datings refactoring
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index be3e06848..821a89ac4 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -1891,9 +1891,25 @@ class BaseHistorizedItem(
new_item.history_m2m = saved_m2m
values = new_item.m2m_listing(hist_key, create=True) or []
hist_field = getattr(self, hist_key)
- hist_field.clear()
- for val in values:
- hist_field.add(val)
+ if hasattr(hist_field, "clear"):
+ hist_field.clear()
+ for val in values:
+ hist_field.add(val)
+ continue
+ # manage related field (not real m2m)
+ # # clear removed values
+ for current_value in hist_field.all():
+ current_values = current_value.history_compress()
+ has_value = False
+ # clear non existant
+ for idx, value in enumerate(values[:]):
+ if value.history_compress() == current_values:
+ values.pop(idx) # remove existing to not create them
+ has_value = True
+ break
+ if has_value:
+ continue
+ current_value.delete()
# force label regeneration
self._cached_label_checked = False
self.save()