1

我不确定它是我正在做的事情还是它是一个错误,但我在 a TabularInline(django admin using grappelli) 中的添加按钮有一些奇怪的行为。我的内联课程是:

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,但我对该语言不是很熟悉,所以我不太确定我在寻找什么。

还有其他人得到这种行为吗?有明显的解决方案吗?

4

2 回答 2

2

这是一个错误。我在 github 上打开了一个问题,因为我们将它用作 Grappelli 的问题跟踪器(https://github.com/sehmaschine/django-grappelli/issues/316)。

看了之后:隐藏按钮的可见性是一个 css 问题,用https://github.com/sehmaschine/django-grappelli/commit/da4d500c5e3b8f8dba5709b0378396131fad361d修复它

于 2013-04-12T13:24:12.080 回答
0

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

这是同一错误的票(3年前):

https://code.djangoproject.com/ticket/13023

来自凯文的经验:

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.

于 2013-04-12T13:59:30.913 回答