Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting values of QuerySet in django

how can I get value of course_code in this QuerySet?

<QuerySet [{'course_code': 11}]>
like image 263
Ali Soltani Avatar asked Feb 04 '18 08:02

Ali Soltani


2 Answers

Use this

someTable.objects.all()[0]['course_code']

or

someTable.objects.values_list('course_code', flat = True)
like image 138
laplace Avatar answered Sep 21 '22 22:09

laplace


course_qs = <whatever query gave you the queryset>
for course in course_qs:
    print(course['course_code'])
like image 32
unixia Avatar answered Sep 24 '22 22:09

unixia