<type 'exceptions.AttributeError'> 'Row' object has no attribute 'unknown'
def get_category_list(post):
category_id_list = db(db.Post_in_category.post_id == post.id).select(db.Post_in_category.category_id)
category_list = []
for category_id in category_id_list:
category_list.append(db.Category[category_id["category_id"]])
return category_list
db.Post.category_list = Field.Virtual(
lambda row: get_category_list(row.Post)
)--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/tTWYuhhGr8I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
def posts():
grid = SQLFORM.grid(db.Post)
return dict(grid=grid)Ingresar el código aquí... I does not work, sadly.
| web2py™ | Version 2.7.4-stable+timestamp.2013.10.14.15.16.29 |
|---|
Traceback (most recent call last):
File "/home/eduardo/PycharmProjects/gblog/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/home/eduardo/PycharmProjects/gblog/web2py/applications/gblog/controllers/admin.py", line 19, in <module>
File "/home/eduardo/PycharmProjects/gblog/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/home/eduardo/PycharmProjects/gblog/web2py/applications/gblog/controllers/admin.py", line 13, in posts
grid = SQLFORM.grid(db.Post)
File "/home/eduardo/PycharmProjects/gblog/web2py/gluon/sqlhtml.py", line 2374, in grid
value = row[str(field)]
File "/home/eduardo/PycharmProjects/gblog/web2py/gluon/dal.py", line 7062, in __getitem__
raise ae
AttributeError: 'Row' object has no attribute 'unknown'
timestamp = db.Table(db, 'timestamp',
Field('created_on', 'datetime', default=request.now, writable=False, readable=False),
Field('created_by', db.auth_user, default=auth.user_id, writable=False, readable=False),
Field('updated_on', 'datetime', update=request.now, writable=False, readable=False),
Field('updated_by', db.auth_user, update=auth.user_id, writable=False, readable=False))
db.define_table("Post",
Field("title", label="Title"),
Field("body", "text", label="Content"),
timestamp
)
db.define_table("Comment",
Field("author", default="anonymous", label="Author"),
Field("body", label="Content"),
Field("post_id", "reference Post", writable=False, readable=False),
timestamp
)
db.define_table("Category",
Field("title", label="Title"),
Field("parent_id", "reference Category", default=None),
timestamp
)
db.define_table("Post_in_category",
Field("post_id", "reference Post"),
Field("category_id", "reference Category"),
timestamp
)
def get_category_list(post_id):
category_id_list = db(db.Post_in_category.post_id == post_id).select(db.Post_in_category.category_id)
category_list = []
for category_id in category_id_list:
category_list.append(db.Category[category_id["category_id"]])
return category_list
db.Post.category_list = Field.Virtual(
lambda row: get_category_list(row.Post.id)
)