开发者

how to filter for objects with time

so lets say I have a simple class Final and I want to filter the results for the past 2 days by the cr开发者_开发百科eated field, how do I do this? When I populate the final class it has a utc created time, but I need the difference of that time and currently this is along the line of what I want done below, but I am unsure on how to get a difference in a query for all items?

class Final(db.Model):
    name = db.StringProperty()
    created = db.DateTimeProperty()

now = datetime.datetime.now()
##d = now - created
##if d.days > 2:
    ## I could loop along something like this but that would be too slow


results = Final.all()
results.filter('created =',##what do i do here?) ##would created >, and then now - 2days work?


I would try:

results.filter('created > ', now - datetime.timedelta(days=2))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜