1

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?

aquavitae
  • 17,414
  • 11
  • 63
  • 106

2 Answers2

2

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

parsch
  • 146
  • 1
  • 6
  • Thanks! Do you have any idea how to patch it? My knowledge of jquery is too limited to know where to start. @catherine: Yes. – aquavitae Apr 12 '13 at 13:55
  • No, I'm currently using Django 1.4 – are there any improvements concerning that bug in 1.5? – parsch Apr 12 '13 at 14:25
  • I fixed that issue with https://github.com/sehmaschine/django-grappelli/commit/da4d500c5e3b8f8dba5709b0378396131fad361d – parsch Apr 12 '13 at 14:26
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.

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.

catherine
  • 22,492
  • 12
  • 61
  • 85
  • Thanks for the answer. It seems the code has changed a lot since then... I can't find the context of the patch at all, but according to the bug report it has been fixed. It looks like a js issue though, because the button only appears when its collapsed. Copying the js over doesn't seem to help. – aquavitae Apr 12 '13 at 14:16