当add权限为Fals时,Djangograppelli add按钮在内联中可见

2024-04-27 00:05:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我不确定这是我正在做的事情还是一个bug,但是我对TabularInline(django admin使用grappelli)中的add按钮有一些奇怪的行为。我的内联类是:

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

“添加”按钮在内联表单集折叠时显示,但在其打开时消失。我试着翻阅相关的jquerys语言,但我不太熟悉这种语言,所以我不太确定我要找的是什么。在

其他人有这种行为吗?有明显的解决办法吗?在


Tags: selfadd语言falsereturnadminrequestdef
2条回答

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

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

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.

有一个由加布里亚赫尔利创建的补丁,可以在不破坏任何其他东西的情况下恢复所需的行为。这是30年前的事了,我不知道它是否还在为django1.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.

相关问题 更多 >