views:

110

answers:

1

Is it possible to override methids for db.Model in Google App Engine? I want to declare beforeSave, afterSave methods, etc.. to create automatic tagging system.

I know there are hooks, but it seems to me a wrong way to solve this issue :)

Thanks!

+1  A: 

Yes, it's possible to override these methods. Have a look at this blog post by Nick Johnson.The hooked model class looks this:

class HookedModel(db.Model):
  def before_put(self):
    pass

  def after_put(self):
    pass

  def put(self, **kwargs):
    self.before_put()
    super(HookedModel, self).put(**kwargs)
    self.after_put()

Read the blog to see how to handle the db.put() method too.

You might also be interested on "derived properties".

jbochi
I really do have to get in faster. ;)
Nick Johnson