Creating child plugins on the fly

Skip to first unread message

Adrian Stern

Jul 26, 2015, 6:43:54 AM7/26/15
to django CMS users

There is a ParentPlugin which allows ChildPlugin to be added to it. Using the admin or onsite edit feature, this works great. 
Since there would be countless ChildPlugins to manually add to ParentPlugin, i'm looking for a way to do this automatically. 

So in the Parents render-method i want to load all the entities to display, create the relevant Plugins, add them to context and render them in the Template is a normally do. 

Maybe i will distinct between child_plugin_instances (manueally added)  and auto_plugin_instances.(created by me)

Those automatically added plugins should not be permanently stored like the manually added ones.

Adrian Stern

Jul 30, 2015, 8:19:01 AM7/30/15
to django CMS users,
I made some progress, but then again, i don't know if it's in the right direction.

Inside the render method of my parent class CMSGridPlugin(CMSPluginBase), i do this:

# get the placeholder instance and plugin instance of the current CMSGridPlugin

def _get_plugin_placeholder(instance, placeholder):
    for placeholder in Placeholder.objects.filter(slot=placeholder):
        plugins = placeholder.cmsplugin_set.filter(
        if plugins.count() == 1:
            return (placeholder, plugins[0])

With this i get: 

Meaning i get the correct placeholder for my current plugin. 

The question remains: 
How do i create a CMSProductPlugin instance, link it to ProductPlugin and set the foreign-Key of entity to a Product from Database? And ultimatly add this plugin to CMSGridPlugin, of which i got the placeholder and instance above. 

---------- some definitions ---------

class CMSGridPlugin(CMSPluginBase):
    model = GridPlugin

class CMSProductPlugin(CMSPluginBase):
    model = ProductPlugin

class ProductPlugin(CMSPlugin):
    entity = models.ForeignKey(Product)

I do not care if i have to save those plugins in Database, but i think it should be possible not to. 


Jul 30, 2015, 8:50:55 AM7/30/15
to django CMS users,
What i want to achieve:

Render a list of Entities (from Product.objects.filter...) in a way, OnSite-Editing of the rendered Entities is possible. 

  • Plugin is configured only once
  • Products can be added any time and thus the state cannot be saved to database
  • Not Just Products but also Service.objects.filter...


Oct 7, 2020, 8:50:11 AM10/7/20
to django CMS users
I currently have exactly the same scenario but unfortunately have no idea how to proceed at all. Did you manage to make it work?
Reply all
Reply to author
0 new messages