1
我正在一個web應用程序中,用戶可以在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)
,但它返回只有一個朋友的帖子。如何從數據存儲中查詢以獲取用戶朋友的所有帖子。感謝