我想爲Django CMS創建一個自定義插件。正如guide顯示的那樣,我創建了一些示例。但是現在我們的目標是創建一個可以從(mysql)數據庫獲取數據的插件。它會加載屬於菜單的所有標題,因爲我想要與目錄類似。Django CMS自定義插件從cms_title加載數據
要從自定義模型中獲取數據,代碼是這樣的:
models.py:
from cms.models.pluginmodel import CMSPlugin from django.db import models class Hello(CMSPlugin): guest_name = models.CharField(max_length=50, default='Guest')
cms_plugins.py:
SE進口CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import ugettext_lazy as _
from .models import Hello
class HelloPlugin(CMSPluginBase):
model = Hello
name = _("Hello Plugin")
render_template = "hello_plugin.html"
cache = False
def render(self, context, instance, placeholder):
context = super(HelloPlugin, self).render(context, instance, placeholder)
return context
plugin_pool.register_plugin(HelloPlugin)
但作爲cms_title
默認屬於Django的CMS,哪些選項是可能的嗎?我在哪裏可以找到名稱爲Title的CMS模型的定義?將它設置爲CMSPlugin實例會是一個糟糕的方法嗎?