web2py,数据库关系和权限

编程入门 行业动态 更新时间:2024-10-25 06:33:23
本文介绍了web2py,数据库关系和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我有这个问题 我有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,数据库关系和权限

本文发布于:2023-10-23 14:07:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:权限   关系   数据库   web2py

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!