开发者

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

开发者 https://www.devze.com 2023-02-07 16:09 出处:网络
How do I perform setup() automatically when a new model instance has been created? class MyModel(bd.Model):

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

精彩评论

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

关注公众号