這是我第一次嘗試製作Django CMS插件。我有以下文件準備就緒:Django CMS插件:無法在界面中看到模型字段
cms_plugins.py
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.models import CMSPlugin
from . import models
class SurveyPluginPublisher(CMSPluginBase):
"""Show Polls entered by Admin."""
cache = False
# model = models.QuickAidPluginModel
module = "Survey"
name = "Awesome Survey v1.0"
render_template = 'survey/_hello.html'
def render(self, context, instance, placeholder):
return context
plugin_pool.register_plugin(SurveyPluginPublisher)
models.py
# encoding: utf-8
from cms.models import CMSPlugin, python_2_unicode_compatible
from django.db import models
from django.core.exceptions import ValidationError
from cms.models import CMSPlugin
class Survey(models.Model):
name = models.CharField(max_length=400)
description = models.TextField()
def __unicode__(self):
return (self.name)
def questions(self):
if self.pk:
return Question.objects.filter(survey=self.pk)
else:
return None
@python_2_unicode_compatible
class SurveyPluginModel(CMSPlugin):
name = models.CharField("Survey Name", max_length=255, default='Survey Name',
help_text='Enter Survey Name')
description = models.CharField("Survey Description", max_length=500, blank=True, help_text='Write Description here')
def __str__(self):
return "Returning some Survey Text"
模板文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>Hi Survey</h2>
</body>
</html
但是,當我編輯頁面的選項,並嘗試加入插件,它顯示了這個屏幕
我想這是因爲你已經在你的插件類中定義了'module'而不是'model',因此它不知道你有什麼字段。這是一個插件類的例子; https://github.com/divio/djangocms-link/blob/master/djangocms_link/cms_plugins.py –