给定以下实体:
class DateTest(db.Model):
dateAdded = db.DateTimeProperty()
#...
从当月获取记录的最佳方法是什么?
给定以下实体:
class DateTest(db.Model):
dateAdded = db.DateTimeProperty()
#...
从当月获取记录的最佳方法是什么?
There are a few ways you can do this. For example, using Query
:
import datetime
from google.appengine.ext import db
q = db.Query(DateTest)
# This month
month = datetime.datetime.today().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
q.filter('dateAdded >= ', month)
results = q.fetch(10)
您可以尝试以下方法:
import datetime
now = datetime.datetime.now()
DateTest.gql("WHERE dateAdded.month:1", now.month)