views:

25

answers:

2

In MySQL you can get the next or previous record based on the key/id. Anyone know how i can achieve this in app engine (im using python) by only knowing/passing the key? Thanks

+1  A: 

There's no way (by default) for an entity to know the next/previous entity.

One thing you could do is give each model a timestamp for the time they were created, then getting the next entity is as easy as selecting the first entity whose timestamp is after XXX.

Jason Hall
A: 

Assuming that by 'next/previous', you mean 'the entity with the key that is lexicographically closest to a given key', yes, you can do this using queries. Supposing your key is in 'my_key', and your model is called MyModel, in Python it would work like this:

q = MyModel.all().filter('__key__ >', my_key)
next_entity = q.get()

q = MyModel.all().filter('__key__ <', my_key)
prev_entity = q.get()
Nick Johnson
thanks seems to be working
monmonja