【发布时间】:2013-12-26 03:34:55
【问题描述】:
这里是新手。我的应用程序名称是 ccad。型号名称为 logbook。用户 A 没有从可用用户权限中编辑、添加或删除日志模型的权限。
所以我尝试隐藏保存、保存并继续编辑、保存并从用户 A 添加另一个按钮。
我遵循了我在 SO 中找到的建议。 Here's 来自 Sid 回答的 picomon 查询。还有daniel the same inquiry。
我最终将以下代码写入我的模板。
change_form.html 位于 {{template folder}}/admin/app_name/model_name/
{% if perms.ccad.add_logbook %}
<li><input type="submit" value="{% trans 'Save ' %}" class="grp-button grp-default" name="_save" {{ onclick_attrib }}/></li>
<li><input type="submit" value="{% trans 'Save and add another' %}" class="grp-button" name="_addanother" {{ onclick_attrib }} /></li>
<li><input type="submit" value="{% trans 'Save and continue editing' %}" class="grp-button" name="_continue" {{ onclick_attrib }}/></li>
{% endif %}
但是没有权限的用户仍然可以看到我提到的按钮。
我也尝试将{% if perms.ccad.add_logbook %} 更改为{% if perms.ccad.can_add_logbook %},但无济于事。
最好的方法是什么?
【问题讨论】:
标签: permissions django-templates django-admin