diff options
| -rw-r--r-- | ishtar_common/forms.py | 20 | ||||
| -rw-r--r-- | ishtar_common/models.py | 6 | 
2 files changed, 14 insertions, 12 deletions
| diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 57f48ff95..7f9c8a400 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -269,18 +269,20 @@ class CustomForm(BSForm):          :return: ((order1, key1, field1), ...)          """          fields = [] -        for field in custom_form.json_fields.values( -                "order", "label", "json_field__name", "json_field__value_type", -                "help_text", "json_field__key").order_by('order').all(): -            key = "data__" + field["json_field__key"] +        q = custom_form.json_fields.values( +            'label', 'help_text', 'order', 'json_field__key', +            'json_field__value_type', 'json_field__name', +        ).order_by('order') +        for field in q.all(): +            key = "data__" + field['json_field__key']              field_cls, widget = forms.CharField, None -            if field["json_field__value_type"] in JSON_VALUE_TYPES_FIELDS: +            if field['json_field__value_type'] in JSON_VALUE_TYPES_FIELDS:                  field_cls, widget = JSON_VALUE_TYPES_FIELDS[ -                    field["json_field__value_type"]] -            attrs = {'label': field["label"] or field["json_field__name"], +                    field['json_field__value_type']] +            attrs = {'label': field['label'] or field['json_field__name'],                       'required': False} -            if field["help_text"]: -                attrs['help_text'] = field["help_text"] +            if field['help_text']: +                attrs['help_text'] = field['help_text']              if widget:                  attrs['widget'] = widget()              if field_cls == widgets.Select2DynamicField: diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 962fc93a1..8c421bac7 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1276,9 +1276,9 @@ class JsonData(models.Model, CachedGen):              return value          choices = set()          splitted_key = key[len('data__'):].split('__') -        for obj in cls.objects.filter( -                data__has_key=key[len('data__'):]).values("data").all(): -            value = obj['data'] +        q = cls.objects.filter( +            data__has_key=key[len('data__'):]).values_list('data', flat=True) +        for value in q.all():              for k in splitted_key:                  value = value[k]              choices.add(value) | 
