How to add plugin to Static placeholder in Django CMS

I am starting to use Static Placeholders in Django-CMS and I want to load speed and create a static "footer" placeholder. Something like:

static_placeholder = StaticPlaceholder(
    name=static_placeholder_code,
    code=static_placeholder_code,
    creation_method=StaticPlaceholder.CREATION_BY_CODE
)
static_placeholder.save()

      

I tried adding TextPlugin with api.add_plugin but got error

add_plugin(
    placeholder=static_placeholder,
    plugin_type='TextPlugin',
    language='en',
)

      

Since static_placeholder is not an instance of Placeholder, add_plugin does not work. in add_plugin function: assert isinstance (placeholder, Placeholder)

What would be the best way to add a TextPlugin to this static placeholder?

+3


source to share


1 answer


StaticPlaceholder

is a model that has two foreign key relationships with the model Placeholder

, one is called draft

, the other is called public

. Both will provide you with a copy Placeholder

.

You can simply use:

add_plugin(
    placeholder=static_placeholder.draft,
    plugin_type='TextPlugin',
    language='en',
)

      

and it will work, but keep in mind that you should always use the draft

above as an example, because when you publish, all the plugins from draft

will be copied to the placeholder public

.



Lately, you are not sure about the specifics of your application, but should point out that when you create a staticplace object in a template, you do not need to create it manually. You can simply:

{% load cms_tags %}

{% static_placeholder 'footer' %}

      

Then a static placeholder will be created or created footer

.

+3


source







All Articles