Volatil3
Volatil3

Reputation: 14998

Django CMS Plugin Development: __init__() got an unexpected keyword argument 'instance'

I am in process of creating Django CMS plugin. So far I have created a form, model and plugin file. I want to save SETTINGS info, but when I go to save it it gives error as mentioned above. Below are details.

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"

Upvotes: 1

Views: 227

Answers (1)

Iain Shelvington
Iain Shelvington

Reputation: 32294

SurveyForm should be a subclass of ModelForm

class SurveyForm(forms.ModelForm):

    class Meta:
        model = SurveyPluginModel

Upvotes: 4

Related Questions