I want to parse a query set to output json data. However I need to make it so that the new jquery ui autocomplete can use it too, and the autocomplete needs the keys label, id and value to be able to read it.
Currently I use:
emp_list = Employees.objects.filter(eng_name__icontains=q_term)
json_serializer = serializers.get_serializer('json')()
json_data = json_serializer.serialize
(emp_list, ensure_ascii=False, fields=('eng_name', 'chi_name'))
and the output is something like
[{"pk": 1, "model": "system.employees",
"fields": {"rank": "manager", "eng_name": "Eli"}},
........]
I want to be able to parse it into something like this instead:
[{"id": 1, "label": "Eli (manager)", "value": "Eli (manager)"}, ....]
what is the best way to do this?
build it in your view then json dump it
something like this, don’t know your actual field names