开发者

how do I instrospect appengine's datastore models?

in order to dynamically create a form, i have to find the property types of a model's properties at runtime.

appengine docs says that Model.properties() will return a dictionary of properti开发者_如何学运维es name and their class type. when i use this method in my code, only the name is returned and the classtype value is always empty.


Model.kind()

E.g., for a model like this:

class LargeTextList(db.Model):
    large_text_list = db.ListProperty(item_type=db.Text)

my_model_instance.kind() returns LargeTextList.


Edit (thanks to OP for clarification):
The property information you seek is there, but you'll need to escape to see it, e.g. in your template:

<p>{{ my_model_instance.properties|escape }}</p>

This returns:

{'large_text_list': <google.appengine.ext.db.ListProperty object at 0x24b1790>}

Edit2:
You can also call properties() on the class itself:

my_model = LargeTextList

and in the template as before (be sure to use the escape filter):

<p>{{ model.properties|escape }}</p>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜