Hi Zeynel,
  How are Item and SiteUser related?

  Why do you want to move the author property off of the Item kind?
For your use-case I would probably consider storing the author's name
on Item entities -- it will make your list page faster.


Robert








On Sun, Jan 16, 2011 at 20:50, Zeynel <[email protected]> wrote:
> Hello,
>
> I have my model like this
>
> class Item(db.Model):
>    title = db.StringProperty()
>    url = db.StringProperty()
>    date = db.DateTimeProperty(auto_now_add=True)
>    author = db.UserProperty()
>
> but now I realized that in order to have a voting algorithm I needed
> to have a separate model for the author and so now I have
>
> class Item(db.Model):
>    title = db.StringProperty()
>    url = db.StringProperty()
>    date = db.DateTimeProperty(auto_now_add=True)
>    vote = db.IntegerPropterty()
>
> class SiteUser(db.Model):
>    author = db.UserProperty()
>
> But in the handler that shows the latest items, I have item.author
> like this:
>
> class Newest(webapp.RequestHandler):
>    def get(self):
>        items = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC
> LIMIT 30")
>
>        self.response.out.write("<ol>")
>        for item in items:
>            self.response.out.write("""<li><a href="%s">%s</a> <br />
>                                           <div style="color: #808080;
> font-size: x-small;"> %s by %s <a href="/item/%s"></a> |
>                                           <a href="http://sarah-for-
> president.appspot.com/item/%s#disqus_thread"></a></div></li><br /> """
> %
>                                           (item.url, item.title,
> item.date.strftime("%B %d, %Y %I:%M%p"), item.author,
> str(item.key().id()),
> str(item.key().id())))
>
>        self.response.out.write("</ol>")
>
> In short, I have item.author inside the for loop. But now, item.author
> does not exist. I think that I need to instantiate the SiteUser like
>
> site_user = SiteUser()
>
> and somehow have site_user.author inside the for loop above.
>
> But I do not know how to do this and I am confused.
>
> This is how the site looks like now: 
> http://sarah-for-president.appspot.com/newest
>
> I would really appreciate help and explanation to understand how to
> achieve this simple task.
>
> Thanks!
>
> --
> 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.
>
>

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

Reply via email to