2013-07-29 30 views
0

我創建了一個顯示最後五個元素的「模型」的「視圖」。我如何創建CMS插件,我可以放入「佔位符」?如何從django視圖創建django-cms插件?

+0

你必須明確你一個CMS插件是什麼意思。這很不清楚。 – 2013-07-29 11:49:42

+0

我可能很愚蠢,或者不太明白什麼需要插件django-cms,或Google翻譯搞砸了,你不明白我想要什麼。我想做的事情,讓我把一個「佔位符」最後5添加到數據庫記錄。 – Atterratio

+0

像最近的博客條目。 – Atterratio

回答

5

爲了創建一個可用於佔位符內部的django-cms插件,您需要have to create a subclass of CMSPluginBase。在你的子類中,你應該重寫render方法,來實現你的自定義渲染。

又見這個例子中(從資料爲準):

# myapp/cms_plugins.py 
from cms.plugin_base import CMSPluginBase 
from cms.plugin_pool import plugin_pool 
from polls.models import PollPlugin as PollPluginModel 
from django.utils.translation import ugettext as _ 

class PollPlugin(CMSPluginBase): 
    model = PollPluginModel # Model where data about this plugin is saved 
    name = _("Poll Plugin") # Name of the plugin 
    render_template = "polls/plugin.html" # template to render the plugin with 

    def render(self, context, instance, placeholder): 
     context.update({'instance':instance}) 
     return context 

plugin_pool.register_plugin(PollPlugin) # register the plugin