开发者

get entities for last 7 days in datastore

i need to fetch entities for the last 7 days, and if fewer than 开发者_运维问答50 entities are fetched extend the range to 10 days, the model is something like:

class MyModel(db.Model):
    title = db.StringProperty()
    date = db.DateTimeProperty(auto_now_add=True)
    plays = db.IntegerProperty()

I also need to order by number of plays descending.

any help is appreciated thanks J


I can't test the code right now but I would do something like :

from datetime import datetime, timedelta

query = MyModel.gql("WHERE date > :1 ORDER BY plays DESC", datetime.now() - timedelta(days=7))
count = query.count()
if count < 50:
   query = MyModel.gql("WHERE date > :1", datetime.now() - timedelta(days=10))
value = query.fetch()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜