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()
精彩评论