Django CMS插件:在中看不到模型字段

2024-09-30 10:27:32 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我第一次尝试制作Django CMS插件。我准备了以下文件:

cms公司_插件.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)

模型.py

^{pr2}$

模板文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h2>Hi Survey</h2>
</body>
</html

但当我得到编辑页面选项并尝试添加插件时,它显示了这个屏幕

enter image description here


Tags: 文件frompyimport插件cmsmodelshtml
2条回答

尝试声明窗体:

在表单.py公司名称:

class SurveyForm(forms.ModelForm):
    class Meta:
        model = Survey
        field = ['name', 'description']

在模型.py公司名称:

^{pr2}$

尝试在您的SurveyPluginPublisher中添加一行model = models.SurveyPluginModel。它需要了解它的模型。在

另外,我建议添加fieldsets作为属性。它允许设计管理界面。不过,这是没有必要的。在

相关问题 更多 >

    热门问题