You declare a property for a model by assigning a property
declaration object to an attribute of the model class. The name of the
attribute is the name of the datastore property. The value is an object
that describes the terms of the declaration. As discussed earlier, the
db.StringProperty object assigned to the
class attribute says that the entity that an instance of the class
represents can only have a string value for its
required=True argument to the
db.StringProperty constructor says that the object is not
valid unless it has a value for the
This can look a little confusing if you’re expecting the class
attribute to shine through as an attribute of an instance of the class, as
it normally does in Python. Instead, the
db.Model class hooks
into the attribute assignment mechanism so it can use the property
declaration to validate a value assigned to an attribute of the object. In
Python terms, the model uses property descriptors to
enhance the behavior of attribute assignment.
Property declarations act as intermediaries between the application and the datastore. They can ensure that only values that meet certain criteria are assigned to properties. They can assign default values when constructing an object. They can even convert values between a data type used by the application and one of the datastore’s native value types, or otherwise customize how values are stored.
db.StringProperty is an example ...