@@ -41,6 +41,7 @@ you would like to use:
41
41
.. code-block ::
42
42
43
43
from django.db import models
44
+ from django.utils.functional import cached_property
44
45
from cms.models.fields import PlaceholderRelationField
45
46
from cms.utils.placeholder import get_placeholder_from_slot
46
47
@@ -152,6 +153,27 @@ Preview buttons:**
152
153
request.toolbar.set_object(obj) # Announce the object to the toolbar
153
154
return render_my_model(request, obj) # Same as preview rendering
154
155
156
+ .. note ::
157
+
158
+ If using class based views, you can set the toolbar object in the ``get_context_data ``
159
+ method of your view and add a stub view usable when you
160
+ :ref: `register the model for frontend editing <register_model_frontend_editing >`.
161
+
162
+ .. code-block :: python
163
+
164
+ from django.views.generic.detail import DetailView
165
+
166
+ class MyModelDetailView (DetailView ):
167
+ # your detail view attributes
168
+
169
+ def get_context_data (self , ** kwargs ):
170
+ context = super ().get_context_data(** kwargs)
171
+ self .request.toolbar.set_object(self .object)
172
+ return context
173
+
174
+ def my_model_endpoint_view (request , my_model ):
175
+ return MyModelDetailView.as_view()(request, pk = my_model.pk)
176
+
155
177
.. note ::
156
178
157
179
If you want to render plugins from a specific language, you can use the tag like
@@ -193,6 +215,8 @@ Let the model know about this template by declaring the ``get_template()`` metho
193
215
194
216
...
195
217
218
+ .. _register_model_frontend_editing :
219
+
196
220
Registering the model for frontend editing
197
221
------------------------------------------
198
222
@@ -202,7 +226,7 @@ The final step is to register the model for frontend editing. Since django CMS 4
202
226
done by adding a :class: `~cms.app_base.CMSAppConfig ` class to the app's `cms_config.py `
203
227
file:
204
228
205
- .. code-block ::
229
+ .. code-block :: python
206
230
207
231
from cms.app_base import CMSAppConfig
208
232
from . import models, views
@@ -212,6 +236,15 @@ file:
212
236
cms_enabled = True
213
237
cms_toolbar_enabled_models = [(models.MyModel, views.render_my_model)]
214
238
239
+ .. note ::
240
+
241
+ If using class based views, use the stub view in ``cms_toolbar_enabled_models `` attribute.
242
+
243
+ .. code-block :: python
244
+
245
+ cms_toolbar_enabled_models = [(models.MyModel, views.my_model_endpoint_view)]
246
+
247
+
215
248
Adding content to a placeholder
216
249
-------------------------------
217
250
0 commit comments