google.appengine.ext.db.Model. However, we decide to extend it and add more useful methods that working on the data.Now (after SVN revision 49), you can create your model by extending from
gaeo.model.BaseModel. This class extends from google.appengine.ext.db.Model, so you can also use the its methods and BaseModel's.Let's show you one of the useful methods in
BaseModel -- update_attributes. By using update_attributes method, you can simply update the attributes of a model. For example, if you defined a model like this:from google.appengine.ext import db
from gaeo.model import BaseModel
class Foo(BaseModel):
x = db.StringProperty()
y = db.IntegerProperty()
z = db.StringProperty()then, you can update the attributes like this:
foo = Foo.gql(......).get()
foo.x = 'abc'
foo.y = 123
foo.z = 'def'
foo.put()or,
foo = Foo.gql(....).get()
foo.update_attributes(x='abc', y=123, z='def')
#no need calling put()or,
foo = Foo.gql(....).get()
foo.update_attributes({'x': 'abc', 'y': 123, 'z': 'def'})
#no need calling put()Please try to use the extended class,
BaseModel, and you will feel easy to manipulate the data.
0 Comments:
Post a Comment