[英]django-ckeditor: uncaught exception using inlines
I have two simple models Question and Choice (one question has multiple choices). 我有两个简单的模型问题和选择 (一个问题有多个选择)。 I have used inline formset to add Choices along with adding Questions (through modelAdmin functionality).
我使用内联formset添加Choices以及添加Questions(通过modelAdmin功能)。
class Question(models.Model):
category = models.CharField(max_length=50)
question_text = RichTextField(max_length=2000, verbose_name="Question Text", blank=True)
class Choice(models.Model):
question = models.ForeignKey(Question)
description = RichTextField(max_length=500, verbose_name="Choice Description")
is_correct = models.BooleanField(default=False)
Now the fields of Choice and Question are RichTextField defined in django-ckeditor . 现在,Choice和Question的字段是在django-ckeditor中定义的RichTextField。 The issue is when I click on "Add another choice" I get an
uncaught exception: [CKEDITOR.editor] The instance "id_choice_set-__prefix__-description" already exists
, which disrupts the ckeditor functionality. 问题是,当我点击“添加另一个选择”时,我得到一个
uncaught exception: [CKEDITOR.editor] The instance "id_choice_set-__prefix__-description" already exists
,这会破坏ckeditor的功能。
Any ideas/suggestions how to fix this issue? 任何想法/建议如何解决这个问题? I think some JS tweaks can help but I have a very limited knowledge in JS/Jquery
我认为一些JS调整可以提供帮助,但我对JS / Jquery的知识非常有限
Thanks 谢谢
Line 66 of django-ckeditor's widgets.py is where your problems seems to originate. django-ckeditor的widgets.py第66行是你的问题似乎来自哪里。
Essentially it seems, the substitution made for final_attr['id']
is where you are getting the __prefix__
from. 从本质
final_attr['id']
,对final_attr['id']
的__prefix__
从中获取__prefix__
地方。 Looking through the framework source code, line 151 of Django's forms/formsets.py is where that value comes from. 查看框架源代码, Django的forms / formsets.py的第151行是该值的来源。 Also, from the source, it seems that value will be replaced by the default prefix ie 'form' in all cases except if you are using
_get_empty_form()
incorrectly somehow. 此外,从源代码来看,似乎值将被默认前缀替换, 即在所有情况下都使用'form',除非您以某种方式错误地使用
_get_empty_form()
。
It would be helpful if you provide/answer the following: 如果您提供/回答以下内容将会有所帮助:
Once your page is rendered, but before you "Add another choice", post the tag attributes from your rendered formset (incl. the management form). 呈现页面后,在“添加其他选项”之前,请从呈现的formset(包括管理表单)中发布标记属性。
Are you using _get_empty_form()
directly at any point in your code? 您是否在代码中的任何位置直接使用
_get_empty_form()
?
Code for the view where you create the formset and where you render it. 用于创建formset的视图的代码以及呈现它的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.