Reputation: 306
I have an array of columns. Like,
fields = ['first_name', 'last_name', 'email']
# this values can be dynamic
I want the values of those columns from the User model.
I tried this.
User.objects.values(fields)
But it doesn't work. It provides a traceback.
AttributeError: 'list' object has no attribute 'split'
Any solution?
Upvotes: 3
Views: 221
Reputation: 933
Here is how you do it:
fields = ['first_name', 'last_name', 'email']
User.objects.values(*fields)
Upvotes: 2