我的解决方案是将日期值像光标一样使用,正如我描述的那样,它是对尼克森的答案的注释…就像这样:
if cursor: # This is not actually a cursor! It is base64 datetime string
cursordate = _strptime(base64.b64decode(cursor)) # _strptime is a local method that converts str to datetime
# IN has a limit for lists: 30 items allowed
listofNewsLists = []
listofMemberLists = [followed_member_list[i:i+30] for i in range(0, len(followed_member_list), 30)]
for eachList in listofMemberLists:
query = NewsItem.all()
query.filter('posted_by IN', eachList).filter('status =', 1)
if cursor:
query.filter('posted_on <', cursordate)
query.order('-posted_on')
listofNewsLists.append(query.fetch(PAGE_SIZE))
newsList = []
if listofNewsLists:
emptyListCount = 0
while len(newsList) < PAGE_SIZE and emptyListCount < len(listofNewsLists):
max = datetime.datetime.min
maxInd = -1
emptyListCount = 0
for i in range(len(listofNewsLists)):
if listofNewsLists[i] == []:
emptyListCount += 1
elif listofNewsLists[i][0].posted_on > max:
max = listofNewsLists[i][0].posted_on
maxInd = i
if max > datetime.datetime.min:
newsList.append(listofNewsLists[maxInd].pop(0))
template_values['cursor'] = base64.b64encode(newsList[-1].posted_on.isoformat())
那是; 我将最后显示的项目的日期值存储为新列表的起点…
除非我有具有相同post_on值的项目,否则这很好(我猜)。