当客户端尝试检索位置时,我无法检索朋友的 ID 和昵称。id 和昵称(以及其他内容字段)存储在 User 表中,朋友关系存储在 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'] = []