'How to extract Data from Django Queryset
How to retrieve the data from Django queryset for use in a variable
When an output is received in below form after running the query
<QuerySet [{'name': 'John'}]>
I want to use the value 'John' in a variable for further processing.
How do I extract this ?
Solution 1:[1]
k = <QuerySet [{'name': 'John'}]>
k[0] = {'name': 'John'}
Queryset is a list.
Solution 2:[2]
Try with values_list()
.
myValues = myQuerySet.values_list()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dKen |
Solution 2 | 4b0 |