我试图在 Django-CMS 文档(http://docs.django-cms.org/en/2.3.5/extending_cms/custom_plugins.html)中复制 2.4 中的示例。但是,每当我在cms_plugins.py下指定模型时class HelloPlugin
,管理员中的整个 CMS 部分都会消失。知道是什么原因造成的吗?
模型.py
from django.db import models
class MyModel(models.Model):
title = models.CharField(max_length=50, null=True, blank=True)
def __unicode__(self):
return self.title
from cms.models.pluginmodel import CMSPlugin
class HelloPlugin(CMSPlugin):
ad = models.ForeignKey('core.MyModel', related_name='plugins')
def __unicode__(self):
return self.ad.title
cms_plugins.py
class HelloPlugin(CMSPluginBase):
model = MyModel
name = _("MyModel Plugin")
render_template = "myplugin.html"
def render(self, context, instance, placeholder):
context['instance'] = instance
return context
plugin_pool.register_plugin(HelloPlugin)