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 管理屏幕中
基础教程推荐
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
