diff --git a/djangocms_bootstrap4/contrib/bootstrap4_grid/cms_plugins.py b/djangocms_bootstrap4/contrib/bootstrap4_grid/cms_plugins.py index a1374dc..a3863b6 100644 --- a/djangocms_bootstrap4/contrib/bootstrap4_grid/cms_plugins.py +++ b/djangocms_bootstrap4/contrib/bootstrap4_grid/cms_plugins.py @@ -89,15 +89,29 @@ def save_model(self, request, obj, form, change): extra['{}_col'.format(size)] = data.get( 'create_{}_col'.format(size) ) + + try: + # django CMS <= 3 + plugin_position = obj.numchild + except AttributeError: + # django CMS >= 4 + plugin_position = obj.placeholder.get_next_plugin_position(obj.language, obj) + col = Bootstrap4GridColumn( parent=obj, placeholder=obj.placeholder, language=obj.language, - position=obj.numchild, + position=plugin_position, plugin_type=Bootstrap4GridColumnPlugin.__name__, **extra ) - obj.add_child(instance=col) + + try: + # django CMS <= 3 + obj.add_child(instance=col) + except AttributeError: + # django CMS >= 4 + obj.placeholder.add_plugin(instance=col) def render(self, context, instance, placeholder): gutter = 'no-gutters' if instance.gutters else ''