我有一个字段:
overtime_50 = fields.Char(readonly=True, default='00:00')
我对这个字段做了一个列表,我得到了这么多列表:
def _compute_sum_50(self):
for record in self:
x = [record.overtime_50]
print(x)
控制台打印:
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
['00:00']
我需要得到这样的东西:
['00:00','00:00','00:00','00:00','00:00','00:00','00:00','00:00','00:00']
我尝试了很多方法,但我只得到这样的结果:
def _compute_sum_50(self):
for record in self:
x = [record.overtime_50]
print(list(chain.from_iterable(x)))
控制台打印:
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
['0', '0', ':', '0', '0']
我能做错什么?
def _compute_sum_50(self):
x = [record.overtime_50for record in self] # Use List Comprehension
print(x)
编辑:Dipen Shah提供的更好解决方案