A wild guess would be that your are not looking at the same entities
in both methods, try to check the entity key using topic.key()
You might also want to check that article about Modeling your data on
App Engine:
http://code.google.com/appengine/articles/modeling.html
Hope that helps.
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine/-/BxbGdTqS6pcJ.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
--
Johan Euphrosine (proppy)
Developer Programs Engineer
Google Developer Relations
Personally, I would probably write this as:
if not self.topic_keys:
return []
return db.get(self.topic_keys)
I would also probably rather not make it a property, but a method
named something like get_topics. That way it is explicit that you'll
be making an RPC. Just a personal preference. ;)
>
> class Topic(db.Model):
> name = db.StringProperty(multiline=True, required=True)
> user_keys = db.ListProperty(db.Key)
>
> @property
> def users(self):
> if len(self.user_keys) == 0:
> return []
> return db.get(self.user_keys)
>
> In the get method of a request handler I tried to retrieve the list of users
> that have participated in the topic
>
> topic_list = Topic.all().filter("name =",topic_id).fetch(limit=1)
See Query.get:
http://code.google.com/appengine/docs/python/datastore/queryclass.html#Query_get
> if len(topic_list) > 0:
> topic = topic_list[0]
> topic_users = topic.users
> ...
After you've rewritten this using Query.get you'll have something like:
topic = Topic.all().filter("name =", topic_id).get()
if topic:
topic_users = topic.get_users()
logging.debug(topic.user_keys)
What happens if you add that logging call? Are you getting keys?
Robert
>
> But doing this gives me a Topic instance where the 'name' property is
> correct but topic.users is empty. However if I try to fetch the topic like
> below, the topic.users I get isn't empty
>
> for tpc in pmwuser.topics:
> if tpc.name == topic_id:
> topic = tpc
> topic_users = tpc.users
>
> What am I doing wrong in the first case? Am I modelling this wrong all
> together? Any help would be appreciated.
>
> Thanks in advance
>
> Simon
>