diff options
Diffstat (limited to 'ishtar_common/models_common.py')
| -rw-r--r-- | ishtar_common/models_common.py | 22 |
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() |
