From ad4981972fcab73e4dadd5ba4a2965b8c1c3ad2c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 4 Nov 2025 18:15:25 +0100 Subject: 🚧 datings refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models_common.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'ishtar_common/models_common.py') 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() -- cgit v1.2.3