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-14 16:19:08 +0100
commit4a21e99df5cffd472acfe26013a350c302429d74 (patch)
treeaccd15795445e560dd56a1815cb8ca74095e42bd /ishtar_common/models_common.py
parentdbd200f4ba696631a37c7f6ee18b422c254f6a49 (diff)
downloadIshtar-4a21e99df5cffd472acfe26013a350c302429d74.tar.bz2
Ishtar-4a21e99df5cffd472acfe26013a350c302429d74.zip
✨ datings refactoring: models, migrations, sheets, admin
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()