Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Values for Models in Google App Engine

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

like image 509
Gautam Avatar asked Dec 18 '11 12:12

Gautam


1 Answers

Use the default attribute, e.g.

class Pet(db.Model):
    name = db.StringProperty(required=True, default="(unnamed)") 
like image 166
Shay Erlichmen Avatar answered Sep 22 '22 02:09

Shay Erlichmen