>>> ppcs.values('price', 'currency__currency_code')
[{'price': Decimal('562.00'), 'currency__currency_code': u'JPY'}]
When using QuerySet.values
, is there a way to alias the key names to something else? For example, rather than the output showing the through-relationship currency__currency_code
, how can I make the dict key called 'currency' like in the following output:
>>> keys = ['price', 'currency']
>>> [dict(zip(keys, v)) for v in ppcs.values_list('price', 'currency__currency_code')]
[{'currency': u'JPY', 'price': Decimal('562.00')}]
The problem with the idea above is that I don't want a list (nor a generator object) at this stage, I want the output to remain a ValuesQuerySet
as in the first example.