Is it possible to set default values for models ? For example consider this model from Appengine Documentation
from google.appengine.ext import db
class Pet(db.Model):
name = db.StringProperty(required=True)
type = db.StringProperty(required=True, choices=set(["cat", "dog", "bird"]))
birthdate = db.DateProperty()
weight_in_pounds = db.IntegerProperty()
spayed_or_neutered = db.BooleanProperty()
owner = db.UserProperty(required=True)
I want to set the default value of name
to be "Unnamed Pet", so if the user doesn't supply it , The default values taken . So is this possible ?
PS : I want this to be done in the model class Pet
itself
Use the default attribute, e.g.
class Pet(db.Model):
name = db.StringProperty(required=True, default="(unnamed)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With