Nick, I've been faced with your exact situation. I have to say I don't understand PreCallHook, and maybe that would be the best approach, but here's what I do know.
Overriding "put" is a bad idea, and as you point out, the override will not be called in a batch put. I found that the most elegant solution was to derive a new type of db.Property, and override its get_value_for_datastore. Then GAE will automatically do what you want regardless of how the entity is being put. On Jan 14, 1:51 am, Eric Ka Ka Ng <[email protected]> wrote: > would a PreCallHook works for your case? > > http://code.google.com/appengine/articles/hooks.html > > - eric > > 2010/1/14 Nickolas Daskalou <[email protected]>: > > > I have a property of a Model that is a hash of another property of the same > > Model, eg: > > > class MyModel(db.Model): > > something = db.StringProperty() > > something_hash = db.StringProperty() > > def generate_hash(self): > > self.something_hash = sha1(self.something) > > > I want generate_hash() to be automatically called just before the entity is > > put() into the Datastore, without the developer having to explicitly call > > entity.generate_hash(). > > > I know I can create a put() method that makes such a call and then calls > > put() on the superclass, but (a) is that the best way to do it, and (b) if > > the put() is part of a batch put (eg. via db.put(entities)), will the put() > > method of each model instance still be called? > > > Nick > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google App Engine" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/google-appengine?hl=en.
-- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
