Consider:
>>>jr.operators.values_list(\'id\')
[(1,), (2,), (3,)]
How does one simplify further to:
[\'1\', \'2\',
Something like this?
x = [(1,), (2,), (3,)]
y = [str(i[0]) for i in x]
['1', '2', '3']
You need to do ..to get this output ['1', '2', '3']
map(str, Entry.objects.values_list('id', flat=True).order_by('id'))
You can use a list comprehension:
>>> mylist = [(1,), (2,), (3,)] >>> [str(x[0]) for x in mylist] ['1', '2', '3']
Use the flat=True
construct of the django queryset: https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.values_list
From the example in the docs:
>>> Entry.objects.values_list('id', flat=True).order_by('id')
[1, 2, 3, ...]