Google app engine NDB:如何检索下一个/上一个实体?

Google app engine NDB:如何检索下一个/上一个实体?,google-app-engine,app-engine-ndb,Google App Engine,App Engine Ndb,我正在为一家工厂编写一个应用程序,我需要为用户提供一种方法来检索NDB中某一类型的下一个(或上一个)实体,但我不知道如何做到这一点。任何帮助/提示将不胜感激 假设我有以下简化模型: from google.appengine.ext import ndb class Product(ndb.Model): prod_id = ndb.StringProperty(required = True) prod_desc = ndb.StringProperty(required =

我正在为一家工厂编写一个应用程序,我需要为用户提供一种方法来检索NDB中某一类型的下一个(或上一个)实体,但我不知道如何做到这一点。任何帮助/提示将不胜感激

假设我有以下简化模型:

from google.appengine.ext import ndb

class Product(ndb.Model):
    prod_id = ndb.StringProperty(required = True)
    prod_desc = ndb.StringProperty(required = True)
    prod_units = ndb.StringProperty(required = True)
    ... other properties
为了允许用户查找特定的产品,我使用下面的查询(“find”来自用户填写的表单)

到目前为止还不错:我为用户提供了一种基于代码(或描述)查找特定产品的方法

现在我需要在显示页面上放置两个名为“上一个”和“下一个”的按钮,我不知道如何检索下一个和上一个产品


我欢迎任何建议。

在这里找到答案:-)可能重复的
Products_Str = 'Products'   # The string ID for the common products ancestor

...
def get_products_key(products_key_str = Products_Str):
    return ndb.Key('Products', Products_Str)

class DisplayProduct(BaseHandler):  # Displays a product found on exact prod_id property 
def post(self):
    search_key = self.request.get('find')
    find_query = Product.query(Product.prod_id == search_key, ancestor = get_products_key()).get()
    ... here I display the one result of the query, i.e. the requested product