How to query google app engine blobstore by creation date and order the results
I need to retrieve the latest set of files from GAE blobstore. Currently my code says
nDays = 10 #this is set at run time
gqlQuery = blobstore.BlobInfo.gql("WHERE filename = :1 ORDER BY creation DESC",<filename>)
cursor = gqlQuery.fetch(nDays)
when I iterate and print 开发者_StackOverflow中文版out the data by calling cursor[i].creation, it doesn't give me the last nDays starting from today. For example, today is August 20. I expect it to give me data from Aug 11 - Aug 20 (I have a file for each day). Instead it gives me data from Aug 13 back a few days.
If i remove the ORDER BY in the gqlquery, it correctly returns all the results (not sorted). If I make the gqlQuery iterable so that I say something like
for filename in gqlQuery:
print filename.creation
it only prints from August 13 back to a few days (about 8 days). I know for a fact there is data up till today. From GAE, I can view the data. Also, the creation date is stamped automatically by Google when the file is uploaded to blobstore.
Anyone know what I'm missing?
I may also miss something, but what's the purpose of "filename = :1" in you query?
This ran correctly against my blobstore:
gqlQuery = blobstore.BlobInfo.gql("ORDER BY creation DESC")
blobs = gqlQuery.fetch(5)
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write("Lasts blobs<br>")
for blob in blobs:
self.response.out.write(blob.filename + "<br>")
Florent
精彩评论