diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-08 11:15:25 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2026-04-08 11:15:25 +0200 |
| commit | 14e2c9e6dd12f930f156cfedce2b984fc08c0def (patch) | |
| tree | 8fe7cd5f5368665fed48831874c6bb24d16f7930 /ishtar_common/utils.py | |
| parent | 22896b4525fd218d828db01dcd28439dc1a56dc9 (diff) | |
| download | Ishtar-14e2c9e6dd12f930f156cfedce2b984fc08c0def.tar.bz2 Ishtar-14e2c9e6dd12f930f156cfedce2b984fc08c0def.zip | |
WIPdevelop-5.0
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) |
