views:

55

answers:

1

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 properties 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.

+1  A: 

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>
Adam Bernier
thanks for the reply. i'm not looking for the kind. but for instance in your example, that large_text_list is a ListProperty. that's what i'm looking for.
python for ever
@python: thanks for the clarification; see edit.
Adam Bernier
exactly what i'm doing. does it have to be on an instance? i'm only getting the keys in my properties dict.
python for ever
No, doesn't need to be an instance. You can call the `kind()` method on the class itself as well. I'll add that as another example in case it helps.
Adam Bernier
weird, it is not working on my side.
python for ever
@python: might help to post the bit of code that isn't working for you; including relevant template code.
Adam Bernier
duh! it's the escape thing :) thanks a lot.
python for ever
Happy to help. Enjoy your holiday weekend (if you're in the US, that is.)
Adam Bernier
Just realised that `<p>` may not be the greatest HTML element to display this information. Ah well, gets the job done.
Adam Bernier