Remove quot;add anotherquot; in Django admin screen(删除“添加另一个在 Django 管理屏幕中)
问题描述
每当我使用对象 B 的外键编辑对象 A 时,对象 B 的选项旁边都会出现一个加号选项添加另一个".如何删除该选项?
Whenever I'm editing object A with a foreign key to object B, a plus option "add another" is available next to the choices of object B. How do I remove that option?
我配置了一个无权添加对象 B 的用户.加号仍然可用,但是当我单击它时,它显示权限被拒绝".太丑了.
I configured a user without rights to add object B. The plus sign is still available, but when I click on it, it says "Permission denied". It's ugly.
我正在使用 Django 1.0.2
I'm using Django 1.0.2
推荐答案
不推荐使用的答案
Django 让这成为可能.
DEPRECATED ANSWER
Django has since made this possible.
您是否考虑过使用 CSS 来简单地不显示按钮?也许这有点太老套了.
Have you considered instead, using CSS to simply not show the button? Maybe that's a little too hacky.
这是未经测试的,但我在想......
This is untested, but I'm thinking...
no-addanother-button.css
#_addanother { display: none }
admin.py
class YourAdmin(admin.ModelAdmin):
# ...
class Media:
# edit this path to wherever
css = { 'all' : ('css/no-addanother-button.css',) }
执行此操作的 Django 文档 -- 媒体作为静态定义
Django Doc for doing this -- Media as a static definition
注意/ 文档说这些文件将带有 MEDIA_URL,但在我的实验中它不是.您的里程可能会有所不同.
Note/ The documentation says the files will be prepended with the MEDIA_URL but in my experimentation it isn't. Your mileage may vary.
如果您发现这种情况适合您,可以快速解决此问题...
If you find this is the case for you, there's a quick fix for this...
class YourAdmin(admin.ModelAdmin):
# ...
class Media:
from django.conf import settings
media_url = getattr(settings, 'MEDIA_URL', '/media/')
# edit this path to wherever
css = { 'all' : (media_url+'css/no-addanother-button.css',) }
这篇关于删除“添加另一个"在 Django 管理屏幕中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除“添加另一个"在 Django 管理屏幕中


基础教程推荐
- 症状类型错误:无法确定关系的真值 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01