I am developing a twitter like microblogging system by using the following models:
class Member(db.Model):
user = db.UserProperty(required=True)
follower_count = db.IntegerProperty(default=0) # members following you
following_count = db.IntegerProperty(default=0) # members you are following
class NewsItem(db.Model):
text = db.StringProperty(required=True)
posted_by = db.ReferenceProperty(reference_class=Member,required=True,collection_name="posted_items")
posted_on = db.DateTimeProperty(auto_now_add=True)
status = db.IntegerProperty(default=1) # 0: deleted
class Follow(db.Model):
member = db.ReferenceProperty(reference_class=Member,required=True,collection_name="followings")
followed_member = db.ReferenceProperty(reference_class=Member,required=True,collection_name="followers")
added_on = db.DateTimeProperty(auto_now_add=True)
In this model structure I retrieve the messages of the members that the current user follows with the following code below:
follow_log_list = Follow.gql('WHERE member = :1 ', member)
followed_member_list = []
for follow_log in follow_log_list:
followed_member_list.append(follow_log.followed_member)
query = NewsItem.all()
query.filter('posted_by IN', followed_member_list)
query.filter('status =', 1)
query.order('-posted_on')
query.with_cursor(cursor)
newsList = query.fetch(10)
template_values['cursor'] = query.cursor()
When query.cursor() method is called I get the following error:
"No cursor available for a MultiQuery
(queries using "IN" or "!="
operators)"
This is normal since in the documentation of cursors this limitation is stated clearly as:
http://code.google.com/appengine/docs/python/datastore/queries.html
"You cannot use cursors with queries that use the IN or != filter operators."
What is the alternative way of getting the posts of followed members?
Thank you,
EDIT: The posted messages were filtered by their status and ordered by their posted date... But the sample did not show it in here, I've changed it...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…