web2py sqlgrid 中的计算字段
Web2py 有多种计算字段的方法,但文档指出惰性字段“默认情况下不会在表中可视化”,因为它们不带有 _ 等属性。事实上,即使请求该字段,它们似乎也无法在 SQLFORM.grid 中使用。 出现错误
AttributeError: 'FieldLazy' object has no attribute 'readable'
当我在字段列表中包含惰性字段时,
db.mytable.myfield = Field.Lazy(lambda row: "calc")
- 。我可以将惰性字段放入网格中吗?
- 显示包含计算字段的网格的推荐方法是什么。
Web2py has several methods for calculated fields, but the documentation states that lazy fields "are not visualized by default in tables" because they don't come with attributes like _. In fact, they don't seem to be able to be available in SQLFORM.grid even if the field is requested. I get the error
AttributeError: 'FieldLazy' object has no attribute 'readable'
When I include a lazy field in the field list.
db.mytable.myfield = Field.Lazy(lambda row: "calc")
- Can I put a lazy field into a grid?
- What is the recommended way to display a grid that includes calculated fields.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,我认为没有一种简单的方法可以在 SQLFORM.grid 中显示虚拟字段。您可以做的是使用“links”参数并将每个虚拟字段添加为链接(如果“links”是字典,则每个项目将成为网格中的单独列)。
请注意,在这种情况下,您不能指定“字段”参数(即,您不能仅指定要包含在网格中的字段的子集)——这是因为虚拟字段函数需要所有字段才能工作。如果您需要隐藏某些字段,则可以将其“可读”属性设置为 False。
另一个选项可能是计算字段。
Unfortunately, I don't think there is an easy way to display virtual fields in SQLFORM.grid. What you can do is use the "links" argument and add each virtual field as a link (if "links" is a dictionary, each item will become a separate column in the grid).
Note, in this case, you cannot specify the "fields" argument (i.e., you cannot specify only a subset of the fields for inclusion in the grid) -- this is because the virtual field function needs all the fields in order to work. If you need to hide some of the fields, you can instead set their "readable" attibute to False.
Another option might be computed fields.