diff options
Diffstat (limited to 'ishtar_common/utils.py')
| -rw-r--r-- | ishtar_common/utils.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index cb6511d9d..2135af3a6 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -2395,6 +2395,22 @@ def get_m2m_values(obj): return hist_values +def update_cached_hierarchy(obj): + updates = {} + for attr in obj.CACHED_HIERARCHY: + # for each type get all hierarchy then eliminate duplicate + cached_attr = f"cached_hierarchy_{attr}" + values = list(sorted( + set(chain(*[ + v.get_label_hierarchy() for v in getattr(obj, attr).all() + ])) + )) + if values != getattr(obj, cached_attr): + updates[cached_attr] = values + if updates: + obj.__class__.objects.filter(pk=obj.pk).update(**updates) + + def manage_m2m(obj, kwargs): obj._queue = kwargs.get("queue", settings.CELERY_DEFAULT_QUEUE) hist_values = get_m2m_values(obj) |
