我正在开发一个webapp,用户可以在Facebook或其他社交媒体上发布和分享朋友,用户的主页将包含他所有的朋友帖子。为了节省用户和他们的朋友我正在使用数据存储区。同样的代码是:
class Tour(db.Model):
username = db.StringProperty()
userid = db.StringProperty()
dst = db.StringProperty()
frm = db.StringProperty()
via = db.StringProperty()
desc = db.TextProperty()
date = db.DateTimeProperty(auto_now_add=True)
`class User(db.Model):
google_user_id = db.StringProperty()
google_display_name = db.StringProperty()
class Friends(db.Model):
owner_user_id = db.StringProperty()
friend_user_id = db.StringProperty()
friends_name = db.StringProperty()`
为了存储用户朋友,我的代码是:
`@staticmethod
def get_and_store_friends(user):
http = decorator.http()
user = service.people().get(userId="me").execute(http=http)
edges = Friends.all().filter('owner_user_id = ', user['id']).run()
db.delete(edges)
friends =service.people().list(userId='me',collection='visible').execute(http=http)
for google_friend in friends.get('items'):
friend_id = google_friend.get('id')
friend_name = google_friend.get('displayName')
friend = User.all().filter('google_user_id = ',google_friend.get('id')).get()
if friend is not None:
edge = Friends()
edge.owner_user_id = user['id']
edge.friend_user_id = friend_id
edge.friends_name = friend_name
edge.put()`
我在查询数据存储区时需要帮助来检索用户朋友的帖子。 我试过这个:
friend_already = Friends.all().filter('owner_user_id =',user['id']).get()
if friend_already is not None:
friend_id = friend_already.friend_user_id
friend_tour = Tour.all().filter('userid =',friend_id)
friends_tour = friend_tour.fetch(100)
但它只回复了一位朋友的帖子。如何从数据存储区查询以获取用户朋友的所有帖子。谢谢
答案 0 :(得分:0)
friend_already行中的.get()
仅返回第一个。
让所有朋友使用:
friend_already = Friends.all().filter('owner_user_id =',user['id']) # no get()
for each in friend_already:
friend_id = each.friend_user_id
....