2015-07-13 61 views
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加载时实现某些功能,或者在添加子窗体时捕获事件,但我不知道如何实现。

回答

1

变化: {%wysiwyg_editor “id_services” %} 上: {%wysiwyg_editor “id_doctors” %}

相关问题