我有一个数据库表,它引用了web2py提供的 auth_user
表:
db.define_table('t_user_business',
Field('f_user_id', type='reference auth_user',
label=T('User Id')),
Field('f_name', type='string',
label=T('Name')),
Field('f_link', type='string',
label=T('Link')),
Field('f_importance', type='integer',
label=T('Importance')),
auth.signature,
format='%(f_user_id)s',
migrate=settings.migrate)
我想设计一个页面,其中包含一个表单,该表单列出了此表中所有经过身份验证的用户的当前条目 . 例如 . 一些东西
db.t_user_business.f_user_id==3
其中 3
替换为当前登录用户的 auth_user.id
值 .
此外,在同一页面上,我希望有一个表单允许用户输入此表的新记录,并在提交时将此验证记录提交到数据库 .
1 回答
当用户登录时,用户ID的值在
auth.user_id
中,因此您可以使用它来设置f_user_id
字段的默认值:使用上述默认值,每当为此表提交
SQLFORM
表单时,f_user_id
的值将自动设置为当前登录用户的ID .请注意,
readable
和writable
属性设置为False
,因此该字段不会出现在表单中 . 它也不会出现在网格中,但您可以通过在定义网格之前更改readable
属性来更改它:要在此表中显示与当前用户关联的记录网格(没有任何视图/编辑/删除按钮),您可以执行以下操作: