开发者

How to create JSON-Response when Entities are referenced via Ancestor?

Maybe my question is somehow unspecific, sorry for that. I'm learning python and app engine (webapp2) at the moment.

I have this class:

class Ice(db.Model):

    """Models an individual Guestbook entry with an author, content, and date."""
    name = db.StringProperty()
    description = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)

    def getTags(self):
        return Tag.all().ancestor(self).fetch(10)

Tags are referenced via ancestor. When I use a jinja-template i can call ice.getTags() foreach Ice.

Now i want to serialize my Ice-object to JSON and want to have all Tags that belong to the Ice-object in my JSON-Output.

This does serialisation for me:

It works okay, but it doesn't include the Tags.

I'm feeling, tha开发者_Go百科t i have to declare Tags as Ice-Attribute, but i don't know how.

class IceHandler(basehandler.BaseHandler):

    def get(self):
        ice_query = model.Ice.all().order('-date')
        ices = ice_query.fetch(10)

        self.response.write(json.encode(ices))

Thanks!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜