polymodel.PolyModel put() overriding
i need to override the put method on my model because i need to do some special stuff while storing the entity.
the code looks something like this:
class Asset(polymodel.PolyModel):
....
def put(self, rpc=None):
# do something special
return self
class Image(Asset):
...
now my problem is that if i call Asset.put() it calls the custom put method while Image.put() uses the default one. If 开发者_StackOverflow社区Asset would be a db.Model this works as expected Image.put() would use the custom put().
how can i make the subclass use the custom function? thx
While it is possible to monkey-patch your classes to allow you to change the behavior of put(), you might be better off writing a method -- call it save() for the sake of argument -- that wraps the put() in a more explicit and obvious fashion and frees you from having to worry about having the patched behaviors being inherited or not by subclasses.
精彩评论