You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/how-to/add-frontend-plugins.rst
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ How to add your own frontend plugin
4
4
Creating the plugin
5
5
-------------------
6
6
7
-
To add custom plugins to Django CMS Frontend, you can follow these steps with in
8
-
your Django app:
7
+
In order to integrate your custom plugins with Django CMS Frontend within your Django app, you should follow these steps.
9
8
10
-
1. **Define a Plugin Model**: In ``models.py`` of your new app, define a model for your
11
-
plugin. Data will be stored in a JSON field of the ``FrontendUIItem`` class. The
12
-
model will in many cases not do much, except defining a short description of
13
-
an instance.
9
+
1. **Define a Plugin Model**:As the first step, you need to define a model for your plugin. This is done in the `models.py` of your Django app. The Plugin model needs to be a **proxy model** of the Django CMS Frontend's `FrontendUIItem` class.
10
+
11
+
The plugin model defines what kind information will be associated with instances of your plugin.
12
+
13
+
Here is an example of a hypothetical plugin model:
14
14
15
15
.. code-block:: python
16
16
@@ -20,16 +20,17 @@ your Django app:
20
20
21
21
classYourPluginModel(FrontendUIItem):
22
22
classMeta:
23
-
proxy =True#Only a proxy model, if NO new fields are added
23
+
proxy =True#MUST be a proxy model
24
24
verbose_name = _("Your Plugin")
25
25
26
26
defshort_description(self):
27
27
returnf"'{self.field_name}'"
28
28
29
+
In this example, the `YourPluginModel` is a proxy of the `FrontendUIItem`, which is the base class for all Django CMS Frontend plugins. It includes a short description method that provides a description for each instance of the plugin.
30
+
29
31
.. note::
30
32
31
-
When adding new fields to the model, you need to remove the ``proxy = True``
32
-
statement in the model's ``Meta`` class.
33
+
Keep in mind proxy models don't allow adding fields to the model. If your plugin needs to include additional fields, consider using ``AbstractFrontendUIItem`` as the base class and remove ``proxy = True`` from the Meta class.
33
34
34
35
2. **Define a Plugin Form**: This form will declare which data to store in the
35
36
``FrontendUIItem``'s JSON field. The ``EntangledModelForm`` will automatically
@@ -40,6 +41,10 @@ your Django app:
40
41
41
42
It will be used in the frontend to create and edit plugin instances.
42
43
44
+
2. **Define a Plugin Form**: You should also define a form that will instruct Django on how to handle the input for creating and editing instances of your plugin. The form should specify which data will be stored in the `FrontendUIItem`'s JSON field.
45
+
46
+
Here is an example of a form for the `YourPluginModel`:
47
+
43
48
.. code-block:: python
44
49
45
50
# forms.py
@@ -59,7 +64,7 @@ your Django app:
59
64
field_name = forms.CharField(max_length=50)
60
65
61
66
3. **Create a Plugin Class**: In the same app, create a file named ``cms_plugins.py``.
62
-
Inside this file, define a class for your plugin by extending `CMSPluginBase`.
67
+
Inside this file, define a class for your plugin by extending ``CMSPluginBase``.
63
68
64
69
.. code-block:: python
65
70
@@ -110,6 +115,8 @@ Remember, developing custom plugins requires a good understanding of Django's an
110
115
CMS's architecture. Additionally, consider the security implications of your plugin,
111
116
especially if it handles user input.
112
117
118
+
119
+
113
120
Extending the plugin
114
121
--------------------
115
122
@@ -181,3 +188,4 @@ and images in your plugin. These mixins are:
181
188
class YourPluginModel(ImageMixin, FrontendUIItem):
182
189
image_field = "image" # The name of the image field in the config JSON
0 commit comments