django-ckeditor:使用内联未捕获异常
我有两个简单的模型问题和选择(一个问题有多个选择)。我使用内联表单集添加选择以及添加问题(通过 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)
现在 Choice 和 Question 的字段是 django-ckeditor 中定义的 RichTextField。问题是,当我单击“添加另一个选择”时,我收到一个未捕获的异常:[CKEDITOR.editor] 实例“id_choice_set-__prefix__-description”已存在
,这会破坏 ckeditor 功能。
有什么想法/建议如何解决这个问题?我认为一些 JS 调整可以有所帮助,但我对 JS/Jquery 的了解非常有限,
谢谢
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).
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. 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.
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
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,并在此处找到了修复程序。
这是由于Inline使用造成的,请尝试安装fork版本来尝试。
虽然已经过去了 6 个月,但希望这可以帮助那些遇到类似问题的人。
I encountered similar issue and found a fix here.
It's caused by Inline usage,try install the forked version to have try.
Though 6 months pass,hope this help those who got similar issue.
django-ckeditor 的 widgets.py 第 66 行这似乎是你的问题的根源。
从本质上讲,对
final_attr['id']
的替换似乎是您从中获取__prefix__
的地方。查看框架源代码,第151行Django 的 forms/formsets.py 是该值的来源。另外,从源代码来看,在所有情况下,值似乎都会被默认前缀“form”替换,除非您以某种方式错误地使用了_get_empty_form()
。如果您提供/回答以下内容,将会很有帮助:
呈现页面后,但在“添加其他选择”之前,发布呈现的表单集(包括管理表单)中的标记属性。
您是否在代码中的任意位置直接使用
_get_empty_form()
?用于创建表单集和呈现表单集的视图的代码。
Line 66 of django-ckeditor's widgets.py is where your problems seems to originate.
Essentially it seems, the substitution made for
final_attr['id']
is where you are getting the__prefix__
from. Looking through the framework source code, line 151 of Django's forms/formsets.py is where that value comes from. Also, from the source, it seems that value will be replaced by the default prefix i.e. 'form' in all cases except if you are using_get_empty_form()
incorrectly somehow.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).
Are you using
_get_empty_form()
directly at any point in your code?Code for the view where you create the formset and where you render it.