Is it possible to set default value of field in data model to id() of the data model?
something like
class MyModel(db.Model):
myID = db.IntegerProperty(default=self.id())
desc = db.StringProperty()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t. The default you’re setting there is in a class variable, and will be the same for all instances created after the class definition is read. If
self.id()actually made sense in this context (it doesn’t;selfis undefined), you’d be getting something like the id of the class, and assigning it as the default to all new instances.The id isn’t actually assigned to the entity until it is written to the datastore, so you can’t, in principle, know what it is at the time of instantiation. You can set a property to the id after you’ve written the entity, but you almost certainly don’t really want to do this anyway.