覆盖 Google App Engine 中的保存、放置、获取等...方法 [英] Override save, put, get, etc... methods in Google App Engine

查看:17
本文介绍了覆盖 Google App Engine 中的保存、放置、获取等...方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Google App Engine 中覆盖 db.Model 的方法?我想声明beforeSave、afterSave等方法来创建自动标记系统.

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 :)

谢谢!

推荐答案

是的,可以覆盖这些方法.看看这个 博客尼克·约翰逊 (Nick Johnson) 发表的帖子.上钩的模型类看起来像这样:

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()

阅读博客以了解如何处理 db.put() 方法.

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

您可能还对"派生属性".

这篇关于覆盖 Google App Engine 中的保存、放置、获取等...方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆