Skip to content

How to get QuerySet values separately?

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 ?


There are many ways you can acheive it. For example:

for item in queryset:

or using values_list():

for item in queryset.values_list('field_name', flat=True):

If you want the first two values of a queryset, then do this:

values = queryset.values_list('field_name', flat=True)
variable_one = values[0]
variable_two = values[1]