Django-tinymce: using different options for different instances

I have a model c HTMLFieldthat can be edited using the TinyMCE control in admin. However, I would like to provide various features of TinyMCE depending on which instance of the model is being edited. How can i do this?

(For example, if the user is editing an instance SimplePagewhose slug is technologies, I want TinyMCE to use the default CSS file, but if editing SimplePageit is slug ticker, I want to use a different CSS file.)

+3
source share
1 answer

, Media ModelAdmin JavaScript CSS ( ). JavaScript , .

: "admin/ your-app" "admin/your-app/your-model" (. Django).

"change_form.html" - :

{% extends "admin/change_form.html" %}
{% block extrahead %}
<script type="text/javascript" charset="utf-8">
    var MYAPP_objectSlug = "{{ original.slug|escapejs }}";
</script>
{{ block.super }}
{% endblock %}

"change_form.html" extrahead, JavaScript slug (original - ).

JavaScript, tinyMCE.init CSS   JavaScript MYAPP_objectSlug.

if (MYAPP_objectSlug == "ticker"){
    var MYAPP_cssFile = "../css/special.css"; // change to your path
} else {
    var MYAPP_cssFile = "../css/default.css"; // change to your path
}

tinyMCE.init({
    ...
    content_css : MYAPP_cssFile,
    ...
});
+1

Source: https://habr.com/ru/post/1733874/


All Articles