如何随着时间过滤对象

时间:2010-07-17 18:26:21

标签: python google-app-engine

所以我想说我有一个简单的类Final,我想在创建的字段中过滤过去2天的结果,我该怎么做?当我填充最后一个类时,它有一个utc创建的时间,但我需要那个时间的差异,目前这是我想要在下面做的行,但我不确定如何在所有查询中找到差异项目

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?

1 个答案:

答案 0 :(得分:3)

我会尝试:

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