1
我有一个用户数据库和一个水果数据库,用户填写一个勾选框来选择他们拥有的水果。选择所有的字段为真
在配置文件中,我想反映这些信息,但我无法弄清楚我将如何查询web2py中的数据库以显示所有设置为True
的布尔字段。
可以用SQL查询完成,还是需要筛选选择用户水果记录的结果?
这里是我的DB模式:
db.define_table('fruit',
Field('id', 'reference auth_user'),
Field('apple','boolean',label=T('Apple')),
Field('apricot','boolean',label=T('Apricot')),
Field('cherry','boolean',label=T('Cherry')),
Field('fig','boolean', label=T('Fig')),
Field('lychee','boolean', label=T('Lychee')),
Field('peach','boolean', label=T('Peach')),
Field('pear','boolean', label=T('Pear')),
Field('plum','boolean', label=T('Plum')))
这里是我的控制器(这显然行不通它只是返回<Set 0>
)。
我试图从谷歌搜索几个不同的组合,但没有具有期望的结果:
def profile():
id = auth.user.id or redirect(URL('default', 'index'))
user = db.auth_user[id]
fruit = db.fruit(id=id)
produce = db(fruit == True)
return dict(user=user, produce=produce)
谢谢你的解释。 这个完美的作品 – 4BY 2013-04-08 16:15:21