2017-02-13 66 views
0

我正在創建Django CMS插件。到目前爲止,我已經創建了一個表單,模型和插件文件。我想保存設置信息,但是當我去保存時,它會給出上面提到的錯誤。以下是詳細信息。Django CMS插件開發:__init __()得到了一個意外的關鍵字參數'instance'

cms_plugins.py

from cms.plugin_base import CMSPluginBase 
from cms.plugin_pool import plugin_pool 
from cms.models import CMSPlugin 

from src.survey.forms import SurveyForm 
from . import models 


class SurveyPluginPublisher(CMSPluginBase): 
    """Show Polls entered by Admin.""" 

    cache = False 
    form = SurveyForm 
    model = models.SurveyPluginModel # Must add to show stuff. 
    module = "Survey" 
    name = "Awesome Survey v1.0" 
    render_template = 'survey/_hello.html' 


plugin_pool.register_plugin(SurveyPluginPublisher) 

forms.py

from django import forms 
from src.survey.models import Survey 

models.py

class SurveyForm(forms.Form): 
    # all_surveys = Survey.objects.only('name') 
    # surveys = forms.ModelChoiceField(queryset=all_surveys) 
    headline = forms.CharField(max_length=255, help_text='Enter Headline') 
    description = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 100}),help_text='Enter Description') 

models.py

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" 
+0

子類中你在哪裏得到這個錯誤?顯示* full *回溯。 –

回答

2

SurveyForm應該是ModelForm

class SurveyForm(forms.ModelForm): 

    class Meta: 
     model = SurveyPluginModel 
+0

'django.core.exceptions.ImproperlyConfigured:禁止創建沒有'fields'屬性或'exclude'屬性的ModelForm; SurveyForm需要更新。 ' – Volatil3

+1

'fields ='__all __''整理出來。謝謝 – Volatil3

相關問題