开发者

Manipulating dates in the datastore

开发者 https://www.devze.com 2022-12-20 14:32 出处:网络
I\'ve recently been playing around with Google\'s AppEngine and I seem to have gotten stuck. I\'m trying to create a query that selects posts that are before a certain date (in this case, the date is

I've recently been playing around with Google's AppEngine and I seem to have gotten stuck. I'm trying to create a query that selects posts that are before a certain date (in this case, the date is now - 1 day). I've tried a few different methods in order to accomplish this, but none have worked. One o开发者_如何转开发f which involved converting all the dates to UNIX time and running a query like this:

db.GqlQuery("SELECT __key__ FROM Post WHERE date-84600 < %s LIMIT 10, ORDER BY date DESC" % time.time())

But after trying that, I got a syntax error which told me GQL didn't have support for operations such as subtracting in the queries.

Does anyone have any idea as to how I could accomplish this?

Thanks in advance


What happens if you build your query using methods?

query = Post.all()
query.filter('date < ', datetime.datetime - 84600)
results = query.fetch(limit=10)


You need to move the math outside of the query:

db.GqlQuery("SELECT __key__ FROM Post WHERE date < :1 LIMIT 10, ORDER BY date DESC", (time.time() - 84600))
0

精彩评论

暂无评论...
验证码 换一张
取 消