How to query specified minutes from datetime kind of gae datastore? eg: “xx:20:xx”
-
26-10-2019 - |
Question
i have a problem using Google App Engine Datastore.
My db class:
class pm25(db.Model):
pttime=db.DateTimeProperty()
Datastore:
pttime
2011-11-01 12:00:00
2011-11-01 12:20:00
2011-11-02 08:00:00
.....
What i want to do is get the entities which time is 20 past any hour.eg: XXXX-XX-XX XX:20:XX How do i write this gql?
Thanks in advance ofive
Solution
This query isn't possible with the model above, because minutes are not indexed. To accomplish this, you'll need to store minutes explicitly at write time. You can do this easily with DerivedProperty:
class pm25(db.Model):
pttime = db.DateTimeProperty()
pttime_minute = DerivedProperty(lambda self: self.pttime.minute)
With this change, you can query pttime_minute
like any other integer.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow