다음 커서와 함께. 이 함수는 요청에서 매개 변수를 읽는 매개 변수를 사용합니다.
def retrieve_dbs(query, order=None, limit=None, cursor=None, **filters):
''' Retrieves entities from datastore, by applying cursor pagination
and equality filters. Returns dbs and more cursor value
'''
limit = limit or config.DEFAULT_DB_LIMIT
cursor = Cursor.from_websafe_string(cursor) if cursor else None
model_class = ndb.Model._kind_map[query.kind]
if order:
for o in order.split(','):
if o.startswith('-'):
query = query.order(-model_class._properties[o[1:]])
else:
query = query.order(model_class._properties[o])
for prop in filters:
if filters.get(prop, None) is None:
continue
if type(filters[prop]) == list:
for value in filters[prop]:
query = query.filter(model_class._properties[prop] == value)
else:
query = query.filter(model_class._properties[prop] == filters[prop])
model_dbs, more_cursor, more = query.fetch_page(limit, start_cursor=cursor)
more_cursor = more_cursor.to_websafe_string() if more else None
return list(model_dbs), more_cursor
그런 방식으로 호출 할 수 있습니다. entity_db 및 entity_dbs 확장을 사용하여 내 변수가 엔티티 객체를 참조 함을 나타냅니다. * _db 및 * _dbs는 하나 이상의 결과가있을 경우 정의합니다.
entity_dbs, entity_cursor = retrieve_dbs(
model.Entity.query(),
limit=limit, # Your limit parameter
cursor=cursor, # The cursor if you want to grab a batch of next results
order=order,
)
어떻게 "커서를 나중에 가져 옵니까?" 이 답변을 보았습니다 : http : //stackoverflow.com/questions/4840731/how-to-use-cursor-for-pagination? rq = 1 그러나 무슨 일이 일어나고 있는지 잘 모르겠습니다. – tjones
query.get()을 호출 한 후 query.cursor()를 호출하여 커서를 가져옵니다. 다음 버튼을 클릭 할 때 다음 쿼리를 실행하면 다음 쿼리에서 커서를 전달합니다. docs : https://developers.google.com/appengine/docs/python/datastore/queryclass#Query_run을 참조하십시오. – dragonx