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'
精彩评论