'"Return option list with children(s) json response.'

def get(self, request, *args, **kwargs):

    results_dict = {}
    results = self.get_list()
    if results:
        flat_results = [(group, item) for entry in results for (group, items) in self.get_item_as_group(entry) for item in items]
        if self.q:
            q = self.q.lower()
            flat_results = [(g, x) for (g, x) in flat_results if (q in x.lower())]
        for (group, value) in flat_results:
            results_dict.setdefault(group, [])
            results_dict[group].append(value)
    return http.HttpResponse(json.dumps({'results': ([{'id': x, 'text': x} for x in results_dict.pop(None, [])] + [{'id': g, 'text': g, 'children': [{'id': x, 'text': x} for x in l]} for (g, l) in six.iteritems(results_dict)])}))
