I need your help to order listed item.
I am trying to make apps that can send message to his/her friends ( just like social feeds ). After watching Bret Slatkin talk about create microblogging here's my code:
content = ndb.TextProperty()
created = ndb.DateTimeProperty(auto_now=True)
receivers = ndb.StringProperty(repeated=True)
user_loggedin = self.request.cookies.get("name")
user_loggedin = None
receive = MessageIndex.query(MessageIndex.receivers == user_loggedin)
receive = receive.fetch()
message_key = [int(r.key.parent().id()) for r in receive]
messages = [Message.get_by_id(int(m)) for m in message_key]
for message in messages:
You can use the message keys in an 'IN' clause in the Message query. Note that you will need to use the parent() key value, not the id() in this case.
# dtStart, dtEnd are datetime values message_keys = [r.key.parent() for r in receive] query = Message.query(Message._key.IN(message_keys), Message.created>dtStart, Message.created<dtEnd) query = query.order(Message.created) # or -Message.created for desc messages = query.fetch()
I am unsure if you wish to simply order by the Message created date, or whether you wish to filter using the date. Both options are catered for above.