質問

I have ListProperty's in an entity that contains two time objects that represent a business' open and closing times for a day of the week:

mon_hours = db.ListProperty(datetime.time)
tue_hours = db.ListProperty(datetime.time)
wed_hours = db.ListProperty(datetime.time)
thu_hours = db.ListProperty(datetime.time)
fri_hours = db.ListProperty(datetime.time)
sat_hours = db.ListProperty(datetime.time)
sun_hours = db.ListProperty(datetime.time)

When I query this entity using the current time AND chain the filters to properly return only records where the list has a time greater and less than, it fails with 0 results:

now = datetime.datetime.now()
q = Place.all()           
q.filter('mon_hours <=', now.time()).filter('mon_hours' >=', now.time())

However, when I remove one of the filters, it returns results, albiet the wrong ones:

now = datetime.datetime.now()
q = Place.all()           
q.filter('mon_hours <=', now.time())

When I manually set the minutes to 00, it works for some reason:

q = Place.all()           
q.filter('mon_hours <=', datetime.datetime(1970,1,1,10,00).time()).filter('mon_hours' >=', datetime.datetime(1970,1,1,10,00).time())

This last query is the desired results but the time needs to be the current time with arbitrary minutes.

WTF?!

役に立ちましたか?

解決 2

My bad. I made the assumption that app engine worked on list properties like mongodb. If two inequality filter are applied to a list property, one value in the list has to match both. The successful results at 00 and 30 minute marks where artifacts of using >=, <= where one value was matching both.

Doh.

他のヒント

Is this code you give exactly what you tried? Note that the datastore doesn't like range filters that indicate an empty range, and returns no results in that case -- so if e.g. you actually ran something like q.filter('a <', t).filter('a >=', t) that would explain your results.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top