Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Add link" shown when options "extra" and "max_num" equal 0 #54

Closed
timur-orudzhov opened this issue Aug 27, 2016 · 9 comments
Closed

"Add link" shown when options "extra" and "max_num" equal 0 #54

timur-orudzhov opened this issue Aug 27, 2016 · 9 comments

Comments

@timur-orudzhov
Copy link

timur-orudzhov commented Aug 27, 2016

I've set options for my NestedTabularInline like this:

class PackageItemInline(nested_admin.NestedTabularInline):
model = PackageUnit
extra = 0
max_num = 0

But nothing changed, I still see "add link". Could anyone explain what the problem is ?

@fdintino
Copy link
Member

fdintino commented Sep 9, 2016

Could you provide some context? What purpose does an inline with max_num = 0 serve?

@timur-orudzhov
Copy link
Author

@fdintino when we set max_num=0 and extra=0 for common inlines, "add link" disappear, but for for nested inline it does not work.

@j2kun
Copy link

j2kun commented Jun 27, 2017

I don't know why this was closed, but it is indeed a bug with this project. max_num = 0 should disable the "add another" button from inlines.

@fdintino
Copy link
Member

fdintino commented Jun 27, 2017

@j2kun it was closed because 02eb051 should fix this issue. Specifically, this line should cause the add another button to be hidden. Is that not the case for you? Could you share the version of Django you are using, whether you are using any django skins such as grappelli or django-suit, and whether you are doing any other customizations with the admin (e.g. other admin enhancement modules, custom change_form.html template, etc.)

@j2kun
Copy link

j2kun commented Jun 27, 2017

This is happening for me with a vanilla admin panel for django 1.10. My admin looks roughly like the following, with FooBatch foreign-keying to Foo, which foreign keys to FooContainer.

class FooBatchInline(nested_admin.NestedTabularInline):
    model = FooBatch
    fields = ('created', 'batch_size', 'realized_count')
    readonly_fields = fields
    can_delete = False
    max_num = 0
    extra = 0

    def has_add_permission(self, request):
        return False


class FooInline(nested_admin.NestedTabularInline):
    model = Foo
    fields = (...)
    readonly_fields = fields
    can_delete = False
    extra = 0
    max_num = 0
    classes = ('collapse',)
    inlines = [
        FooBatchInline,
    ]

class FooContainerAdmin(DjangoObjectActions, nested_admin.NestedModelAdmin):
    model = FooContainer
    ...
    inlines = [FooInline]

@j2kun
Copy link

j2kun commented Jun 27, 2017

(the has add permission was a hailmary)

@fdintino
Copy link
Member

Huh, that's weird. I'm having difficulty reproducing. The following are screenshots from running tox -e py27-dj110 -- --selenium=chrome TestTabularInlineAdmin.test_add_item_to_empty (this selenium test); the first is TabularItemInline without a max_num defined, the second with max_num = 0:

TabularItemInline without max_num

TabularItemInline with max_num=0

@j2kun
Copy link

j2kun commented Jun 27, 2017

I'll keep looking into it.

@theladyjaye
Copy link

Maybe related? I get the add and remove buttons when max_num = 1 but only when deriving from nested_admin.*Inline. If I return to deriving from just admin.StackedInline, for example I don't get any buttons (the expected behavior)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants