我正在使用自定义Django CMS插件,遇到需要嵌套内联的情况。下面是我的模型结构。
aws cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name FreeStorageSpace --region us-east-2 --start-time 2019-01-12T20:00:00Z --end-time 2019-01-12T23:59:00Z --period 3600 --statistics Minimum
"Datapoints": [
{
"Timestamp": "2019-01-12T21:00:00Z",
"Minimum": 19796946944.0,
"Unit": "Bytes"
},
{
"Timestamp": "2019-01-12T23:00:00Z",
"Minimum": 19792580608.0,
"Unit": "Bytes"
},
{
"Timestamp": "2019-01-12T22:00:00Z",
"Minimum": 19794690048.0,
"Unit": "Bytes"
},
{
"Timestamp": "2019-01-12T20:00:00Z",
"Minimum": 19798822912.0,
"Unit": "Bytes"
}
],
"Label": "FreeStorageSpace"
我理想地需要嵌套内联。因此,由于Link模型与CardPanel具有m:1的关系,而CardPanel与Panel模型具有m:1的关系,因此我希望能够添加包含多个Link模型的多个CardPanels。通过Django中的ModelAdmin实现此目的的最佳方法是什么?
答案 0 :(得分:1)
如果您是在此处创建的插件,那么从3.0开始,这些只是managed by the frontend:
在新系统中,
Placeholders
及其插件不再在管理站点中管理,而仅在前端进行管理。
因此,CMSPlugins
的各种属性对此很有用,其中包括CMS随附的一些标准插件。如果它是用于插件的,那么您也不需要在模型上指定plugin
属性。
我会调整您的插件类和相应的模型,使其更像;
# models.py
from cms.models.fields import PlaceholderField
class CardPanel(CMSPlugin):
title = models.CharField(max_length=50)
image = FilerImageField(
null=True,
blank=True,
related_name="navigation_vertical_link_image"
)
content = PlaceholderField('card_panel_content')
# cms_plugins.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .models import CardPanel
@plugin_pool.register_plugin
class CardPanel(CMSPluginBase):
""" Plugin to contain card panels """
model = CardPanel
parent_classes = ['Panel'] # Include this if a card panel only exists in a panel
@plugin_pool.register_plugin
class Panel(CMSPluginBase):
""" Plugin to contain card panels """
model = CMSPlugin
allow_children = True # Allow the Panel to include other plugins
child_classes = ['CardPanel']
通过在PlaceholderField
上包含CardPanel
,您可以呈现模型实例的占位符,并以与将CMS插件添加到页面的方式相同的方式将CMS插件添加到该实例。这样,您可以根据需要添加任意数量的链接插件,如果不使用that plugin,则可以使用页面链接或外部链接。
这样在模板中呈现一个占位符字段;
{% load cms_tags %}
{% render_placeholder card_panel_instance.content %}
PlaceholderField
也可以向admin注册; http://docs.django-cms.org/en/latest/how_to/placeholders.html#admin-integration