django-cmsdjangocms-text-ckeditor

Ckeditor "Convert the HTMLField to a Placeholderfield and configure the placeholder to only accept TextPlugin"


Perhaps I do not understand some simple thing. I’m reading the documentation for the second day and don’t understand how to use ckeditor in django-cms, in a third-party plugin.

Here is written:

Usage as a model field If you want to use the widget on your own model fields, you can! Just import the provided HTMLField like so:

from djangocms_text_ckeditor.fields import HTMLField And use it in your models, just like a TextField:

class MyModel(models.Model): myfield = HTMLField(blank=True) This field does not allow you to embed any other CMS plugins within the text editor. Plugins can only be embedded within Placeholder fields.

If you need to allow additional plugins to be embedded in a HTML field, convert the HTMLField to a Placeholderfield and configure the placeholder to only accept TextPlugin. For more information on using placeholders outside of the CMS see:

http://docs.django-cms.org/en/latest/how_to/placeholders.html

Currently HTMLField is working and after reading the instructions I don’t understand how I can "convert the HTMLfield to a Placeholder and configure the placeholder to only accept TextPlugin" in a third party plugin which was fully integrated into django-cms. I have never created placeholders in third party plugins.

My goal is so that in a third party plugin I can set a text box in which I can edit the text using formatting features. I am using the latest Django-CMS. By default, it has djangocms_text_ckeditor.

Thank you!

models.py:

[..]

    from djangocms_text_ckeditor.fields import HTMLField

    class Question(models.Model):
    content = HTMLField(blank=True)
[..]

template

[..]
{% load cms_tags %}
[..]


    {% for field in form %}
    {{ field }}
    {% endfor %}

[..]

My textarea looks like this:

<textarea name="content" cols="40" rows="10" class="CMS_CKEditor" data-ckeditor-basepath="/static/djangocms_text_ckeditor/ckeditor/" id="id_content"></textarea>

I noticed that through the admin panel it was possible to use the editor for this new textarea, but nothing has changed on the site for a user. Visually it is an ordinary textarea


Solution

  • I found the solution. I have to include the "{{ form.media }}" tag in the templates

      <form method="post" enctype="multipart/form-data" novalidate>
        {% csrf_token %}
        {{ form.media }}
        [..]