Django管理员-如何使“inlines”可折叠?

时间:2022-09-12 09:09:46

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

使用“fieldsets”,可以通过指定CSS类“折叠”来使其可折叠。如何对“inlines”执行相同的操作?谢谢你!

3 个解决方案

#1


9  

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

目前,django不支持开箱即用的可折叠inlines。这张票可能会给你一些提示。

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.

不过,您可以通过向模板添加一些javascript轻松实现这一点。有许多插件可以帮助您实现这一点。向模板添加js的方法是使用ModelForm覆盖ModelAdmin表单,并使用appropiate js脚本设置它的媒体类。

Hope this helps.

希望这个有帮助。

#2


27  

In Django 1.10+:

在Django 1.10 +:

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

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

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

#3


8  

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

查看这个代码片段,您只需包含jQuery(已经包含了Django)。

#1


9  

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

目前,django不支持开箱即用的可折叠inlines。这张票可能会给你一些提示。

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.

不过,您可以通过向模板添加一些javascript轻松实现这一点。有许多插件可以帮助您实现这一点。向模板添加js的方法是使用ModelForm覆盖ModelAdmin表单,并使用appropiate js脚本设置它的媒体类。

Hope this helps.

希望这个有帮助。

#2


27  

In Django 1.10+:

在Django 1.10 +:

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

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

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

#3


8  

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

查看这个代码片段,您只需包含jQuery(已经包含了Django)。