I want to do pretty much the same like in this ticket at djangoproject.com, but with some additonal formatting. From this query
>>> MyModel.objects.values('cryptic_value_name')
[{'cryptic_value_name': 1}, {'cryptic_value_name': 2}]
I want to get something like that:
>>> MyModel.objects.values(renamed_value='cryptic_value_name')
[{'renamed_value': 1}, {'renamed_value': 2}]
Is there another, more builtin way or do I have to do this manually?
It’s a bit hacky, but you could use the
extramethod:This basically does
SELECT cryptic_value_name AS renamed_valuein the SQL.Another option, if you always want the renamed version but the db has the cryptic name, is to name your field with the new name but use
db_columnto refer to the original name in the db.