实施问题:无法获得dicts列表(Json obj)

时间:2013-09-13 21:21:33

标签: python json list dictionary sqlalchemy

当客户端尝试检索位置时,我无法检索朋友的ID和昵称。存储在用户表中的id和昵称(以及其他内容字段)和存储在Friend表中的朋友关系。我是SQLAlchemy和python的新手一般,所以任何帮助将不胜感激。

obj = encoders.to_json(self, Loc.LOC_JSON_ATTRS)

my_friend_ids = user.Friend.select_friend_ids(requestor_id)

friend_creators = session.query(user.User). \
              join(bc.Bc). \
              filter(and_(
                  user.User.id.in_(my_friend_ids),
                  requestor_id == bc.Bc.creator_id, 
                  self.id == bc.Bc.location_id)). \
              all()


obj['friend_list'] = [{'id': friend.id, 'nickname': friend.nickname} \
                     for friend in friend_creators]
#print obj
if not obj['friend_list']:
    print "empty"

else:
    obj['num_created'] = 0
    obj['num_phollowing'] = 0
    obj['num_collected'] = 0
    obj['friend_list'] = []

0 个答案:

没有答案