The .values()
method will return you a result of type ValuesQuerySet
, which you usually need in most cases.
But if you want, you can turn ValuesQuerySet
into your own Python list using Python list comprehension, as shown in the example below.
result = Blog.objects.values() # return ValuesQuerySet object list_result = [entry for entry in result] # converts ValuesQuerySet into Python list return list_result
I find this helps if you write unit tests and have to argue that the expected return value of the function matches the actual return value, in which case both expected_result
and actual_result
must be of the same type (e.g. a dictionary).
actual_result = some_function() expected_result = {
Arthur Rimbun Sep 08 '14 at 5:51 on 2014-09-08 05:51
source share