When a query returns a set of records, values_list returns a list of values. A json or a dictionary is more useful when the data needs to be sent as an http json response
values = list(TestModel.objects.values_list('clustering_key', flat=True))
returns [19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 0L]
values = list(TestModel.objects.values_list('clustering_key','name'))
returns [[19L,abc], [18L,def], [17L,ghi]]
Returning a json is more useful because http calls quite often expect json responses
It becomes hard for the user to always convert a list to a json as there is no in-built method for it.
A method for returning a json or a dict(which can easily be converted to a json) would be very helpful
This sounds like a good feature to have, and one that could easily build on the existing values_list method. I think it might be more appropriate to leave values_list as is and provide a new method for it; maybe .values_map. , what do you think? , would that solve your problem?
In case you don't have a converter function in place, a succinct way to deal with this could be something like
(I haven't tested that, but that's the comprehension I reach for)
I agree that it might be better to add this feature. I think that implementing something similar to Django would be good: .values() returns dictionaries. (and .values_list() is used for list and list of nametuple). +1