[Answered ]-I want to convert Python models list to Dictionary

2👍

If you want dictionaries in a list use .values():

taskNameList = Task.objects.values()

>>> print(taskNameList)
[{'id': 1, 'name': 'i am the first task', ...}, ...]

If you want tuples in a list use .values_list():

taskNameList = Task.objects.values_list()

>>> print(taskNameList)
[(1, 'i am the first task'), ...]

Leave a comment