0
votes

How can one search for ndb models based on key inequality?

For example, for a string one can use:

 def add_inequality_filter(query, attr, given)
     end = given + u'\ufffd'
     return query.filter(attr >= given, attr < end)

 add_inequality_filter(query, "key", "abc.")

If key were an ordinary string property this would work, however the key is a ModelKey.

Comparing the key (or _key) to a string triggers a BadValueError. There does not appear to be a documented way to create a ModelKey (or equivalent) for comparison.

When I try to filter on __key__ > (the db way) I get a Cannot filter a non-Node argument.

The db to ndb documentation certainly indicates that this should be possible.

1

1 Answers

0
votes

To answer my own question, the given and end in this need to be ndb.Key instances, whereas I had only attempted ModelKey, KeyProperty and strings.