我不确定是我在做什么,还是有个bug,但我在TabularInline中的add按钮有一些奇怪的行为(使用grappelli的django admin )。我的内联类是:
class FieldInline(admin.TabularInline):
model = models.Field
classes = ('grp-collapse grp-closed',)
fields = ('number', 'year', 'area')
extra = 0
def has_add_permission(self, request):
return False
def has_delete_permission(self, request, obj):
return False“添加”按钮在内联窗体集折叠时出现,但在其打开时消失。我试着深入研究了相关的jquery,但我不太熟悉这种语言,所以我不太确定我在寻找什么。
其他人也有这种行为吗?有明显的解决方案吗?
发布于 2013-04-12 21:24:12
这是一个bug。我在github上打开了一个问题,因为我们将它用作Grappelli (https://github.com/sehmaschine/django-grappelli/issues/316)的问题跟踪器。
看过这个之后:隐藏按钮的可见性是一个css问题,用https://github.com/sehmaschine/django-grappelli/commit/da4d500c5e3b8f8dba5709b0378396131fad361d修复了这个问题。
发布于 2013-04-12 21:59:31
The new javascript made this impossible because the "Add Another" button was controlled by max_num, and ignored a value of 0. The javascript ignored a value of 0 because max_num has a default value of 0, and all the code using it had taken to equating max_num = 0 with being "off". So you can't actually have a maximum of 0. It's not possible.
Gabrial Hurley创建了一个补丁,可以在不破坏任何其他行为的情况下恢复所需的行为。这是3年前的事了,我不知道它是否仍然适用于Django 1.5。只需尝试:)
https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff
这是同一个bug的罚单(3年前):
https://code.djangoproject.com/ticket/13023
来自Kevin on experience:
I ran into the same issue because I had the static admin content in a directory that was outside of django's install. Copying the Django 1.5 static content from django/contrib/admin/static/admin/js/ to STATIC_ROOT/admin/js fixed the issue.
https://stackoverflow.com/questions/15966633
复制相似问题