google app engine - String conversion within GAE webapp template -
i trying create string of key of referenceproperty
within webapp template:
assume following simple datastore model:
def user(db.model): first_name = stringproperty() last_name = stringproperty() def email(db.model): user = referenceproperty(user) email = emailproperty()
i pass list of email entities webapp template in list named member_list. within template, want create string of key of each email entity's 'user' property use in url, such as:
{% member in member_list %} <a href="/member_handler/{{insert_string_of_member.user_key_here"}}>blah</a>
i realize pass string of key template, prefer string conversion in template if possible; have tried various permutations of str()
, _ str_
no avail.
since know entity in question member
instance, , presumably won't have parent entity, it's simpler (and produces nicer urls) use key name or id of member, rather full string key. can user.key().name()
(user.key.name
in django template) or user.key().id()
. 1 need depends on whether created entity key name or not.
if have email object, there's no need fetch user
key. instead, call email.user.get_value_for_datastore(member)
, return key
object of user
references. can extract relevant field wish. there's no way in django, though, you'll either need outside django , pass in, or add method email
class returns key.
once have id or name , want fetch user
object references, call user.get_by_id(id)
or user.get_by_key_name(name)
appropriate.
Comments
Post a Comment