Question

I'm not sure if its something I'm doing or if its a bug, but I have some strange behaviour with the add button in a TabularInline (django admin using grappelli). My inline class is:

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

The add button appears when the inline formset is collapsed, but disappears when its open. I have tried digging through the jquerys involved, but I'm not very familiar with the language so I'm not too sure what I'm looking for.

Does anyone else get this behaviour? Is there an obvious solution?

Was it helpful?

Solution

This is a bug. I openend an issue for that on github as we use it as issue-tracker for Grappelli (https://github.com/sehmaschine/django-grappelli/issues/316).

After taking a look at that: The visibility of the hidden button was an css-issue, fixed it with https://github.com/sehmaschine/django-grappelli/commit/da4d500c5e3b8f8dba5709b0378396131fad361d

OTHER TIPS

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.

There is a patch create by Gabrial Hurley to restores desired behaviour without breaking anything else. This is 3years ago and I don't know if it still working for Django 1.5. Just try :)

https://code.djangoproject.com/attachment/ticket/13023/13023_inlines_patch.diff

Here is the ticket for that same bug (3 years ago):

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

From 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top