How I can to get values from QuerySet separately? The result of my QuerySet now is
<QuertSet[<value: 5>, <value:90>]>
How I can get 5, 90 to separate variable ?
Advertisement
Answer
There are many ways you can acheive it. For example:
JavaScript
x
3
1
for item in queryset:
2
print(item.field_name)
3
or using values_list()
:
JavaScript
1
3
1
for item in queryset.values_list('field_name', flat=True):
2
print(item)
3
If you want the first two values of a queryset, then do this:
JavaScript
1
6
1
values = queryset.values_list('field_name', flat=True)
2
3
variable_one = values[0]
4
5
variable_two = values[1]
6