Atterratio
Atterratio

Reputation: 466

How create django-cms plugin from django views?

I created a "view" of the "model" which showing the last five elements. How I can create CMS plugin, that I could put into "placeholder"?

Upvotes: 0

Views: 1749

Answers (1)

Bouke
Bouke

Reputation: 12198

In order to create a plugin for django-cms that can be used inside a placeholder, you have to create a subclass of CMSPluginBase. Within your subclass you should override the render method, to implement your custom rendering.

See also this example (taken from the documentation):

# 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

Upvotes: 5

Related Questions