From 14a0da5cb7a794008227cc5c35beadc5f8060b93 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 2 Nov 2021 18:19:03 +0100 Subject: JSON types: multi valued choices --- ishtar_common/models_common.py | 16 +++++++++++++--- 1 file changed, 13 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 e67b78d67..b1c291bee 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -1077,12 +1077,22 @@ class JsonData(models.Model, CachedGen): q = cls.objects.filter(data__has_key=key[len("data__") :]).values_list( "data", flat=True ) + multi = False for value in q.all(): for k in splitted_key: value = value[k] - choices.add(value) - choices = [("", "")] + [(v, v) for v in sorted(list(choices))] - cache.set(cache_key, choices, settings.CACHE_SMALLTIMEOUT) + if isinstance(value, list): + multi = True + for v in value: + if v: + choices.add(v) + else: + choices.add(value) + c = [] + if not multi: + c = [("", "")] + c += [(v, v) for v in sorted(list(choices))] + cache.set(cache_key, c, settings.CACHE_SMALLTIMEOUT) return choices -- cgit v1.2.3