1
我有內聯formset。我使用django-wysiwyg在一些字段上設置所見即所得編輯器。
加載頁面時,一切正常。我使用{% wysiwyg_editor form.worktime.auto_id %}
來設置字段的編輯器。
但是當我動態地向inlineformset添加一個表單時,沒有編輯器出現。
這裏是形式: 如何將django-wysiwyg設置爲內聯formset中的字段?
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加載時實現某些功能,或者在添加子窗體時捕獲事件,但我不知道如何實現。