2

给定以下实体:

class DateTest(db.Model):
    dateAdded = db.DateTimeProperty()
    #...

从当月获取记录的最佳方法是什么?

4

2 回答 2

7

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)
于 2012-07-23T23:01:45.507 回答
1

您可以尝试以下方法:

import datetime
now = datetime.datetime.now()

DateTest.gql("WHERE dateAdded.month:1", now.month)
于 2012-07-23T22:53:53.477 回答