views:

38

answers:

2

I have a model User which appears as a ReferenceProperty in another model, Group.

When I create a form for Group, using Meta, the form's values contain lots of generated strings. I'd like to stop this, and use the username field of User instead.

I already define a key_name. However, str(user.key()) still gives a generated string. I could override key(), but that would be bad. Any thoughts? I want the Group form to use usernames for the ModelChoiceProperty values, and the form to still validate and save. Currently the form prints the string value of key(), according to the source.

A: 

The key() in a db.model is an object that contains a bunch of different information, including the kind of object, its name and an id.

So I'm thinking that key().name() would return what you want?

In the docs, it describes all of this.

mlsteeves
I'm sorry, I was very unclear in my description. Hopefully its clearer now. Thanks for the answer :)
Paul Biggar
A: 

Having thought about this a little bit harder, I think the correct answer is "don't do that". The Entitys will still have keys, and those keys will correspond to a generated string. The form would have to be hacked to make it work too, so this looks like a ton of hassle to essentially make the code a tiny bit prettier looking.

Paul Biggar