开发者

How to create a new property in google app engine

I'm new to google apps engine. I want to have a something like:

class demo(db.model)
 user = db.UserProperty() 
 date = db.DateProperty(au开发者_运维技巧to_now=False, auto_now_add=False)
 weekly = SomeNewProperty()
 ...

How do I create this "SomeNew" property? I read some docs about it but didnt understand what to do. Thanks


The different property types specify the type of the property. You can't easily define your own types (and I don't think that this is what you're after).

Take a look at this page to see a list of different property classes.

For example to add a new boolean property weekly you'd write:

weekly = db.BooleanProperty()

If you want a "complex" property, then you can model that as its own model and use a ReferenceProperty like this:

class WeeklyInfo(db.Model):
   user = db.UserProperty() 
   date = db.DateProperty(auto_now=False, auto_now_add=False)
   confirm = db.BooleanProperty()

class Demo(db.Model):
  someData = db.StringProperty()
  weekly = db.ReferenceProperty(WeeklyInfo)


You can subclass db.Property to create new types of properties. See this article for information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜