[Django]-Django admin – how to make "inlines" collapsible?

9👍

currently django does not support collapsible inlines out-of-the-box. This ticket might give you some pointers.

Nevertheless you can easly achive this by adding some javascript to your template. There are numerous plugins out there that can help you achieve this. The way to add a js to a template is overriding a ModelAdmin form with a ModelForm and setting it’s Media class with the appropiate js script.

Hope this helps.

👤rasca

89👍

In Django 1.10+:

class MyModelInline(admin.TabularInline):
     model = MyModel
     classes = ['collapse']

https://docs.djangoproject.com/en/stable/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.classes

8👍

Check out this snippet, and you just need to include jQuery (already with Django).

Leave a comment