Query For Model By Key
What I'm trying to do is query the datastore for a model where the key is not the key of an object I already have. Here's some code: class User(db.Model): partner = db.SelfRefe
Solution 1:
There's a really easy way around this: Retrieve two records, and filter out the user's own one, if it's present.
def text_message(self, msg):
user = User.get_or_insert(msg.sender)
if not user.partner:
# user doesn't have a partner, find them one
other = db.Query(User).filter('partner =', None).fetch(2)
other = [u for u in other if u.key() != user.key()]
if other:
# connect user with other[0]
else:
# no one to connect to!
Post a Comment for "Query For Model By Key"