Issue
I have a model Employees
and I would like to have a QuerySet of all rows, but with some specific fields from each row, and not all fields.
I know how to query all rows from the table/model:
Employees.objects.all()
I would like to know how to select fields for each of the Queryset element. How can I do that?
Solution
Employees.objects.values_list('eng_name', flat=True)
That creates a flat list of all eng_name
s. If you want more than one field per row, you can't do a flat list: this will create a list of tuples:
Employees.objects.values_list('eng_name', 'rank')
Answered By - Daniel Roseman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.