I have a little application where I am passing messages between users. My model for the message is like this
class Message(db.Model):
from = db.UserProperty()
sent_to_users = db.ListProperty(db.Key)
I send the message to users if they are online, so when I detect that a user is online I send any message that has not already been sent to them. I do message.sent_to_users.append(user) in the /chat/presence/available handler. To indicate that a message has already been sent to user
My question is how do I filter out messages that have already been sent to a user. According to the section on inequality filter in queries a != translates to two queries for greater than and lesser than and the results are then combined. Which needless to say does not work in the case of a list of Keys. Basically members_not_sent_message = Message.all().filter('sent_to_users !=', available_user).fetch(100) does not work.
Is there a way to find values not in a ListProperty, or do I have to go through each item and find messages which have not been sent? Or is there another design for a system like this that circumvents this GAE datastore limitation (if there is one in this case) ?
Inequality filters on list properties don’t really work. As you know, inequality filters run separate “less than value” and “greater than value” queries under the hood, and then concatenate the results. List properties with multiple values will have multiple hits in the same index, so if you filter out one item you’ll always match another.
Consider keeping two lists: besides the
sentlist, keep anot_sentlist, and query that.