如何在内联formset中将django-wysiwyg设置为字段?

时间:2015-07-13 11:08:45

标签: django django-wysiwyg

我有内联formset。我使用django-wysiwyg在某些字段上设置WYSIWYG编辑器 加载页面时,一切都很完美。我使用{% wysiwyg_editor form.worktime.auto_id %}在字段上设置编辑器 但是当我动态地向inlineformset添加一个表单时,没有编辑器出现 这是表格:

class CommentForm(forms.ModelForm):

    class Meta:
        model = Comment
        fields = '__all__'

InstitutionDoctorsFromSet = inlineformset_factory(Institution, Doctor, fields='__all__', extra=1)

模板:

  <form class="the_form" enctype="multipart/form-data" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        {% wysiwyg_editor "id_services" %}
        <fieldset>
            <legend>Doctors:</legend>
            {{ doctor_form.management_form }}
            {% for form in doctor_form %}
                {{ form.id }}
                <div class="inline {{ doctor_form.prefix }}">
                    {{ form.as_p }}
                    {% wysiwyg_editor form.worktime.auto_id  %}
                </div>
            {% endfor %}
        </fieldset>
        <input class="btn btn-default" type="submit" name="submit" value="Update"/>
    </form>

如果我在浏览器控制台中运行以下js代码 - 编辑器出现: django_wysiwyg.enable('ckeditor', 'id_doctor_set-3-regime'),其中id_doctor_set-3-regime是字段的id,我需要有一个编辑器。但是可能有很多领域,所以我需要更灵活的解决方案 我想我需要在加载formset时实现一些东西,或者在添加子窗体时捕获一个事件,但我不知道如何。

1 个答案:

答案 0 :(得分:1)

变化: {%wysiwyg_editor&#34; id_services&#34; %} 上: {%wysiwyg_editor&#34; id_doctors&#34; %}