4👍
You can use itertools chain approach. It will flatten your list.
import itertools
qs = TestModel.objects.values_list('FieldA','FieldB')
qs = list(itertools.chain(*qs))
return qs
1👍
You can use this approach:
fields = ['FieldA','FieldB']
testQS = list(TestModel.objects.values_list(*fields))
result = {field:[] for field in fields}
counter = 0
for item in testQS:
result = {field:[*result[field],item[counter]] for field in fields}
counter +=1
- [Django]-Stop capturing any string based on / for urls in Django (regex)
- [Django]-ImportError for django.contrib.markup
- [Django]-Django-Debug-Toolbar is not showing
- [Django]-How to check django model data type?
- [Django]-Django rest framework & external api
- [Django]-Monkey patched django auth's login, now its tests fail
- [Django]-ModuleNotFoundError: No module named 'ebcli'
- [Django]-How may i install the Python Imaging Library to django environment?
Source:stackexchange.com