by Yan Sheng


之前文章也说了,pre_entry和next_entry根据什么来实现。今天终于解决。 首先,看到GAE讨论上关于自动增1:

[google-appengine] Auto increment
Do you really need this? Remember, an autoincrement means every new
table row has to hit this one field - a situation which won't scale
Consider these alternatives:
* Use the automatically-assigned key for the object (probably the
easiest method)
* Use a random string
* Use some timestamp-derived key (timestamp, then random hash to
prevent collisions)
If you really, really, truly, absolutely need autoincrement, you could
do it by creating some special model for sequence numbers, then
increment it and return the new value in a transaction. However I
again stress that this is almost certainly not what you really want,
and won't scale well.
Every entity has a unique key, in your templates you can use {{ entity.key }}:

<a href="/path?key={{entity.key}}">link</a>

in the request handler you can get the entitiy with:

def get(self):
   key = self.request.get('key')
   entity = db.get(db.Key(key)) #or entity = ModelName.get(db.Key(key))

lrk = Lyrics.get(lrkid)


# 找当前entry的前继和后续
pre_entry = None
next_entry = None
pub_entry_list = list(all_entry.order("-pub_date"))
entry_count = len(pub_entry_list)
for index in range(entry_count):
    if pub_entry_list[index].key().id() == onepost.key().id():
        if index < entry_count-1:
            pre_entry = pub_entry_list[index+1]
        if index > 0:
            next_entry = pub_entry_list[index-1]