开发者

GAE, How do I run a function of a model at the time the new model instance is created?

How do I perform setup() automatically when a new model instance has been created?

class MyModel(bd.Model):  
    setup(self):  
        ...

model = MyMo开发者_开发知识库del()


You can override the __init__() method to do this in addition to its usual work:

class MyModel(db.Model): 
    def __init__(self, *args, **kwargs): 
        super(MyModel, self).__init__(*args, **kwargs)  # run the default code
        self.setup()  # run custom setup code
    def setup(self):
        print 'setup'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜