删除“添加另一个”在Django管理屏幕 [英] Remove "add another" in Django admin screen
问题描述
每当我用对象B的外键编辑对象A时,可以在对象B的选项旁边添加一个加号选项添加另一个。如何删除该选项?
我配置了一个用户,没有添加对象B的权限。加号仍然可用,但是当我点击它时,它显示权限被拒绝。这是丑的。
我正在使用Django 1.0.2
DEPRECATED ANSWER
Django已经成为可能。
您是否考虑过使用CSS来简单地显示按钮?也许这有点太麻烦了。
这是未经测试的,但我在想...
否-addanother-button.css
#_ addanother {display:none}
pre>
admin.py
class YourAdmin(admin.ModelAdmin) :
#...
class Media:
#编辑此路径到
css = {'all':('css / no-addanother-button.css' )}
Django Doc这样做 - 媒体作为静态定义
注意/编辑:文档说明文件将以MEDIA_URL添加,但在我的实验中它不是。您的里程可能会有所不同。
如果您发现这是您的情况,则可以快速解决此问题。
class YourAdmin(admin.ModelAdmin):
#...
class Media:
from django.conf import settings
media_url = getattr(settings,'MEDIA_URL','/ media /')
#编辑此路径到
css = {'all':(media_url +'css / no-addanother-button.css' ,)}
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?
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.
I'm using Django 1.0.2
解决方案DEPRECATED ANSWER
Django has since made this possible.
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 Doc for doing this -- Media as a static definition
Note/Edit: 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管理屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!