I am returning to programming for the Google App Engine, and I found instances in the old unused code in which I wrote constructors for models. This seems like a good idea, but there is no mention of this on the Internet, and I canโt check if it works. Here's a far-fetched example, without error checking, etc .:
class Dog(db.Model): name = db.StringProperty(required=True) breeds = db.StringListProperty() age = db.IntegerProperty(default=0) def __init__(self, name, breed_list, **kwargs): db.Model.__init__(**kwargs) self.name = name self.breeds = breed_list.split() rufus = Dog('Rufus', 'spaniel terrier labrador') rufus.put()
** kwargs are passed to the Model constructor if the model is built with the specified parent or key_name or if other properties are specified (for example, age ). This constructor differs from the default in that it requires the name and breed_list (although it cannot guarantee that they are strings), and it analyzes the breed_list in such a way that the default constructor could not.
Is this a legal form of instantiation, or am I just using static / class functions or methods? And if that works, why aren't custom constructors used more often?
source share