0

i'm trying to add a plugin in a placeholder of a page when i save a model. But i don't know how to pass the parameter "data" to add_plugin() function of the API.

This is how i'm calling the function

page = create_page(self.title, 'page.html', 'es', parent=query_pages[0])
placeholder = page.placeholders.get(slot='News Header')
add_plugin(placeholder, 'ArticlePluginPublisher', 'es', **query_art[0].article)

And when i call add_plugin appears the next error

add_plugin() argument after ** must be a mapping, not Article

1 Answers1

0

Did you check the docs? **query_art[0].article doesn't match the expected arguments as it's an instance;

  • placeholder (cms.models.placeholdermodel.Placeholder instance) – Placeholder to add the plugin to
  • plugin_type (string or cms.plugin_base.CMSPluginBase sub-class, must be a valid plugin) – What type of plugin to add
  • language (string) – Language code for this plugin, must be in LANGUAGES
  • position (string) – Position to add this plugin to the placeholder, must be a valid django-mptt position
  • target – Parent plugin. Must be plugin instance
  • data (kwargs) – Data for the plugin type instance

Data is expected to be something like a dictionary, or something that supports the ** unpacking syntax;

add_plugin(placeholder, 'ArticlePluginPublisher', 'es', **{'article': query_art[0].article})

Check out this example of data or kwargs in a function call;

https://stackoverflow.com/a/1769475/1199464

Community
  • 1
  • 1
markwalker_
  • 12,078
  • 7
  • 62
  • 99