My models look like this:
class Article(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
class Tag(polymodel.PolyModel):
article = db.ReferenceProperty(Article)
name = db.StringProperty()
Now if I want to create a page which lists all the articles that use a
particular tag, I'm doing this:
tagresults = models.Tag.all().order(sort_order).filter("name =
",tag_name).fetch(10)
article_keys = [f.article.key() for f in tagresults]
results = models.Article.get(seed_keys)
Could I be doing that better? Is that the proper way to store things
as a reference, particularly if I want it to be a very fast query, and
preferably saveable in memcache?
Now I also want to do the reverse: create a page that lists articles
in order, and shows every tag used for each article.
articles = models.Article.all().order(sort_order).fetch(10)
for article in articles:
tags = [t for t in article.tag_set]
article.tags = [t.name for t in tags]
That's all I'm doing, and it thus its having to run a query to fetch
the tags, I think.
I think I'm possibly doing both of these wrong, because I want to
prefetch and memcache the parent or child depending on which type of
page (tag pages which show articles, and article pages which show
tags). I've read about a dozen articles on using the
get_value_for_datastore but it doesn't look like it does what I'm
looking for, unless I'm just not understanding it...
Any help?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.