Reputation: 3311
I have a Django query like this and I want to be able to pass the "values" param from a variable. Reason for this I can standardize all my list values otherwise it will be hardcoded on every values.
So for example, this works:
employee_list = Employee.objects.all().values("id", "username").order_by('id')
But I cannot do this. It doesnt work:
val_params = ["id", "username"]
employee_list = Employee.objects.all().values(val_params).order_by('id')
what kind of val_params can i use to pass into values() ? Is there a way to do this ?
Upvotes: 2
Views: 689
Reputation: 24602
You could do
employee_list = Employee.objects.all().values(*val_params).order_by('id')
Upvotes: 5