Introduction
AppEngine has provided a basic model class, google.appengine.ext.db.Model. However, we decide to extend it and add more useful methods that working on the data.
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. For example,
from google.appengine.ext import db
from gaeo.model import BaseModel
class Foo(BaseModel):
x = db.StringProperty()
y = db.IntegerProperty()
Class References
The method helps you construct a many-to-one relationship to another model. For example, if you defined two models:
# application/model/post.py
from google.appengine.ext import db
from gaeo.model import BaseModel
class Post(BaseModel):
author = db.StringProperty()
title = db.StringProperty()
content = db.TextProperty()
post_at = db.DateTimeProperty(auto_now_add=True)
# application/model/comment.py
from google.appengine.ext import db
from gaeo.model import BaseModel
from model.post import Post
class Comment(BaseModel):
author = db.StringProperty()
comment = db.TextProperty()
left_at = db.DateTimeProperty(auto_now_add=True)
Comment.belongs_to(Post)
Then, this method creates ReferenceProperty() in the Comment class whose name is 'post' and set the collection_name in Post as 'comments'. Therefore, you can use post variable in the Comment instance to refer to the post and use comments in the Post instance to refer to the comments.
Instance Methods
update_attributes(self, kwd_dict = {}, **kwds)
This method is used to set multiple attributes at the same time. Originally you may write this codes:
m.x = 123
m.y = 'abc'
m.z = 'foo@example.com'
m.put()
By using this method, your code will become:
m.update_attributes(x=123, y='abc', z='foo@example.com')
This method will automatically invoke the put method at its end.
set_attribute(self, kwd_dict = {}, **kwds)
Same as update_attributes but it doesn't invoke the put method automatically.
An alias to the put method.
An alias to the put method.
|
|