Content creation wizards

Content creation wizards allow you to make use of the toolbar’s Create button in your own applications. It opens up a simple dialog box with the basic fields required to create a new item.

django CMS uses it for creating Pages, but you can add your own models to it.

In the polls_cms_integration application, add a cms_wizards.py file, containing:

  1. from cms.wizards.wizard_base import Wizard
  2. from cms.wizards.wizard_pool import wizard_pool
  3. from polls_cms_integration.forms import PollWizardForm
  4. from polls.models import Poll
  5. class PollWizard(Wizard):
  6. pass
  7. poll_wizard = PollWizard(
  8. title="Poll",
  9. weight=200, # determines the ordering of wizards in the Create dialog
  10. form=PollWizardForm,
  11. description="Create a new Poll",
  12. )
  13. wizard_pool.register(poll_wizard)

A wizard needs a form, so create a forms.py too:

  1. from django import forms
  2. from polls.models import Poll
  3. class PollWizardForm(forms.ModelForm):
  4. class Meta:
  5. model = Poll
  6. exclude = []

Refresh the Polls page, hit the Create button in the toolbar - and the wizard dialog will open, offering you a new wizard for creating Polls.

Note

Once again, this particular example is for illustration only. In the case of a Poll, with its multiple Questions associated with it via foreign keys, we really want to be able to edit those questions at the same time too.

That would require a much more sophisticated form and processing than is possible within the scope of this tutorial.