所以我有这个问题 我有2张桌子 模板(ID,用户ID,模板名称,参考) user_settings(id,user_id,default_template)
So i've this problem i've 2 tables for example templates(id,user_id,template_name,reference) user_settings(id,user_id,default_template)
因此每个用户可以创建许多模板,并且可以在他的设置中选择一个他将始终使用的默认模板
so each user can create many templates and in his settings he can choose a default template that he will always use
现在有很多用户,因此当一个用户想要选择默认模板时,他可以看到所有模板(他自己的模板以及其他用户的模板)
so now there is many users so when a user want to choose a default template, he can see all templates (his own templates and the templates for the other users)
表是这样定义的:
db.define_table('i2l_templates', Field('id','id', represent=lambda id:SPAN(A('view',_href=URL('view_template',args=id)),' | ', A('edit',_href=URL('edit_template',args=id)))), Field('user_id', db.auth_user, default=auth.user_id, writable=False,readable=False, label=T('User Id')), Field('template_name', requires=IS_NOT_EMPTY(), type='string', label=T('Template name')), ... ... ... )db.define_table('user_settings', Field('id','id', represent=lambda id:SPAN(A('view',_href=URL('view_settings',args=id)))), Field('user_id', db.auth_user, default=auth.user_id, writable=False,readable=False, label=T('User Id')), Field('standard_template_id', templates, label=T('Standard Template')), ... ... )
我该怎么做才能使用户仅选择自己的模板!
what should i do to make user choose only his own template!
推荐答案首先,不应该
Field('standard_template_id', templates,是
Field('standard_template_id', db.i2l_templates,对于引用字段,默认格式验证器为IS_IN_DB(db,'<table>.id'),它将选择引用表中的所有记录.但是,您可以覆盖默认验证器并指定记录的子集:
For a reference field, the default form validator is IS_IN_DB(db,'<table>.id'), which will select all records in the referenced table. However, you can override the default validator and specify a subset of records:
requires = IS_IN_DB(db(db.i2l_templates.id==auth.user_id), 'i2l_templates.id', '%(template_name)s')有关数据库验证程序的更多信息,请参见此处.
See here for more on database validators.
更多推荐
web2py,数据库关系和权限
发布评论