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 管理屏幕中


- padding='same' 转换为 PyTorch padding=# 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01