Home > Mobile >  How to remove first brackets from list in django?
How to remove first brackets from list in django?

Time:11-17

I write a query to get the list like this:

tStartEnd = APIHistory.objects.values('status_start','status_end')
codereview = list(tStartEnd) 

expected output is: ['start', 'end'] but I'm getting : [('START', 'END')]

using django query how get the output like this

['start', 'end']

CodePudding user response:

You need to concatenate the items in the tuple:

tStartEnd = APIHistory.objects.values_list('status_start','status_end')
codereview = [item for q in tStartEnd for item in q]

This will thus enumerate over the records q in the queryset, and over the items in the tuple that 1 presents.

  • Related