2017-02-11 17 views
0

これはDjango CMSプラグインを作成する私の最初の試みです。私は、次のしているファイルがREADY:Django CMS Plugin:インタフェースのモデルフィールドが表示されません

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 

しかし、私は編集ページのオプションを持って、ときに

enter image description here

+2

プラグインクラスで 'module'ではなく' module'を定義しているので、あなたが持っているフィールドがわからないからです。プラグインクラスの例を次に示します。 https://github.com/divio/djangocms-link/blob/master/djangocms_link/cms_plugins.py –

答えて

0

フォームを宣言してくださいこの画面を示してプラグイン追加しよう:

forms.py:

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

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') 
    form = SurveyForm 

    def __str__(self): 
     return "Returning some Survey Text" 
0

model = models.SurveyPluginModelを0に追加してみてください。そのモデルについて知っておく必要があります。

また、属性としてfieldsetsを追加することをお勧めします。管理インターフェースを設計することができます。しかし、それは必要ではありません。

関連する問題