db.Model class variables and __init__

2019-07-17 12:12发布

(New to Python and GAE)

I'm looking for an explanation to the use of class variables in db.Model subclasses, which are treated like instance variables. Why are these declared in class scope and not in __init__? Is this some kind of special GAE requirement?

1条回答
你好瞎i
2楼-- · 2019-07-17 12:40

Yes, this is a programming model special to GAE. You can think of the class properties as the table definition. The instance properties are the contents of a row, they are populated on the fly by the metclass db.PropertiedClass.

There is a lot going on under the hood, if you are interested always have a look at the source: http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/db/init.py

查看更多
登录 后发表回答