Closed adlh closed 8 months ago
An interesting fact here, is that almost the same plugin, but as a proxy model (without the added fields bla1
and bla2
, works perfectly well, so maybe this has something to do with the 'untangled' fields.
I'm including my test project with 3 plugins, one non-frontendUI plugin, one using a proxy model and the one described in the bug. bug_report_example_project.zip
@adlh Thank you so much for the detailed bug report. This was extremely helpful! I looked into this.
Let me start with a few comments:
1) Currently, as described in the docs, only additional frontend items without any additional fields are possible (they need to be proxy models).
2) The reason for this is the way django CMS plugins are stored in the database in an abstract way, and how they are "downcasted" to concrete plugins. This only works over one level. Your implementation would require two downcast steps:
a) from generic CMSPlugin
to FrontendUIItem
b) from FrontendUIItem
to CustomFrontendUIItem
3) The solution for most cases is to move the additional database fields to the entangled form, effectively moving the fields from the database to the config
JSON field.
However, I recognize that there is a legitimate use case for your situation, e.g., if you need a reference with guaranteed referential integrity.
There's a shortcoming in djangocms-frontend's set up which I would like to update. Besides FrontendUIItem
which can be used as a base class for proxy models, I propose to introduce AbstractFrontendUIItem
as a base which allows adding model fields.
Then you'd have two options to extend djangocms-frontend plugins:
FrontendUIItem
): The data is stored in the djangocms_frontend_frontenduiitem
table and only form fields can be added to the JSON storage. No model fields to be added. (Probably the vast majority of use cases.)AbstractFrontendUIItem
: The data is stored in a separate table of your app. JSON storage can be used as with djangocms-frontend. You can add model fields. @marksweb Do you have any thoughts on this?
@adlh And yes: The documentation is misleading, since it suggests you can just remove the proxy status of the model. 🤦♂️
Thanks @fsbraun for analyzing the problem. I think I can work with proxy models for the time being. Most of the plugins I'm migrating need only some options or text-fields, so that shouldn't be a problem.
And yes, the docs were really misleading on that part :-D
Fixed with #195
Description
A custom plugin (built as described in the djangocms-frontend docs, with new fields in the model), breaks when copy-pasting it on a page. After pasting it, no new item appears, as expected, and instead of it, the child plugins inside it are pasted into the original plugin (twice).
Steps to reproduce
Steps to reproduce the behavior:
test_plugins
.Create a new custom plugin, like the one described in the docs linked above, with own field(s) in the model:
test_plugins/forms.py
class CustomFrontendUIForm(EntangledModelForm): class Meta: model = CustomFrontendUIItem entangled_fields = { "config": [ "json_field", # This field will be stored in the config JSON ] } untangled_fields = ['bla1', 'bla2'] json_field = forms.CharField(max_length=100)
test_plugins/cms_plugins.py
@plugin_pool.registerplugin class CustomFrontendUIPlugin(CMSUIPlugin): model = CustomFrontendUIItem form = CustomFrontendUIForm module = ('Tests') name = _('FrontendUI Test') render_template = "test_plugins/custom_frontend_plugin.html" allow_children = True
makemigrations
and thenmigrate
.Text
plugin with some text.Expected behaviour
A new instance of the custom plugin should appear with a copy of the child Text plugin inside it.
Actual behaviour
No new plugin is created and the original instance gets duplicates of the child plugins instead.
Screenshots
Additional information (CMS/Python/Django versions)
Using virtualenv with python 3.10 and the following output of
pip freeze
:Do you want to help fix this issue?