8. 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 forms.py file:

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

Then 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. class PollWizard(Wizard):
  5. pass
  6. poll_wizard = PollWizard(
  7. title="Poll",
  8. weight=200, # determines the ordering of wizards in the Create dialog
  9. form=PollWizardForm,
  10. description="Create a new Poll",
  11. )
  12. wizard_pool.register(poll_wizard)

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.