Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin - how to make "inlines" collapsible?

With "fieldsets" you can make it collapsible by specifying the CSS class "collapse". How to do the same with "inlines"? Thank you!

like image 266
Edwin Yip Avatar asked May 07 '10 11:05

Edwin Yip


3 Answers

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

like image 135
Collin Anderson Avatar answered Nov 16 '22 06:11

Collin Anderson


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.

like image 45
rasca Avatar answered Nov 16 '22 07:11

rasca


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

like image 8
Armando Pérez Marqués Avatar answered Nov 16 '22 05:11

Armando Pérez Marqués