1

我有订单结构:

{u'order_id': 12341,
u'status_history': [{u'reason': u'',
                      u'status': u'2000',
                      u'time': datetime.datetime(2013, 7, 31, 11, 52, 47)},
                    {u'reason': u'',
                     u'status': u'6020',
                     u'time': datetime.datetime(2013, 7, 31, 11, 59, 8)},
                    ]
}

我要更新记录。我的查询:

problem_index = 1 # int
db.order.update({'order_id':order_id},
                 {'$set':{'status_history.%s' % problem_index : edited_item}}
)

结果:

AttributeError("'unicode' object has no attribute 'subtype'",)

为什么?

4

1 回答 1

0

哦..递归结构。需要更多的关注。我保存最后一个版本:

last_item  = edited_item
# Need last_item  = copy.copy(edited_item)
if edited_item.has_key('previous versions'):
    edited_item['previous versions'].append(last_item)
于 2013-08-02T08:12:14.367 回答