I want to set the .tzinfo of every datetime instance automatically as soon as it comes out of the datastore.
So if I have
class Message( db.Model ):
creationTime = db.DateTimeProperty()
someOtherTime = db.DateTimeProperty()
## I really want to define a method like this,
## that runs immediately AFTER an instance has
## been refreshed from the datastore
def wakeup( self ):
self.creationTime.tzinfo = self.creationTime.replace( tzinfo=EST )
self.someOtherTime.tzinfo = self.creationTime.replace( tzinfo=EST )
Is it possible to do this in GAE?
I think the best approach is for you to subclass the DateTimeProperty class and override its method make_value_from_datastore:
given suitable tzinfo objects UTC and EST of course (built by pytz or whatever). Of course you could also build a more generic “smart datetime” property class and let it set the timezone of interest from a keyword argument in its
__init__, for example, if you need several different datetime attributes to use different timezones.