how to get obj2.name via obj1.categories(), thanks (gae python)
- by zjm1126
i using google-app-engine webapp ,code is :
class Post(db.Model):
title = db.StringProperty(required=True)
def categories(self):
return (x.category for x in self.postcategory_set)
class Category(db.Model):
name = db.StringProperty()
class PostCategory(db.Model):
post = db.ReferenceProperty(Post)
category = db.ReferenceProperty(Category)
class sss(webapp.RequestHandler):
def get(self):
obj1 = Post(title='hhaa')
#obj1.title = 'haha'
obj1.put()
obj2 = Category()
obj2.name='haha-kao'
obj2.put()
obj3=PostCategory()
obj3.post=obj1
obj3.category=obj2
obj3.put()
self.response.out.write(obj1.categories().get().name)
the error is :
Traceback (most recent call last):
File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 511, in __call__
handler.get(*groups)
File "D:\zjm_code\helloworld\a.py", line 131, in get
self.response.out.write(obj1.categories().get().name)
AttributeError: 'generator' object has no attribute 'get'
so how to get the obj2.name via obj1's method
thanks