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. 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.
现在,Choice和Question的字段是在django-ckeditor中定义的RichTextField。问题是当我点击“添加另一个选择”时,我得到一个未被捕获的异常:[CKEDITOR.editor]实例“id_choice_set -__ prefix __- description”已经存在,这会破坏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
谢谢
2 个解决方案
#1
3
I encountered similar issue and found a fix here.
我遇到了类似的问题,并在此处找到了解决方
It's caused by Inline usage,try install the forked version to have try.
它是由Inline使用引起的,请尝试安装分叉版本试试。
Though 6 months pass,hope this help those who got similar issue.
虽然过了6个月,希望这能帮助那些得到类似问题的人。
#2
2
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. 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.
从本质上看,对final_attr ['id']的替换就是从中获取__prefix__的地方。查看框架源代码,Django的forms / formsets.py的第151行是该值的来源。此外,从源代码来看,似乎值将被默认前缀替换,即在所有情况下都使用'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的视图的代码以及呈现它的位置。
#1
3
I encountered similar issue and found a fix here.
我遇到了类似的问题,并在此处找到了解决方
It's caused by Inline usage,try install the forked version to have try.
它是由Inline使用引起的,请尝试安装分叉版本试试。
Though 6 months pass,hope this help those who got similar issue.
虽然过了6个月,希望这能帮助那些得到类似问题的人。
#2
2
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. 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.
从本质上看,对final_attr ['id']的替换就是从中获取__prefix__的地方。查看框架源代码,Django的forms / formsets.py的第151行是该值的来源。此外,从源代码来看,似乎值将被默认前缀替换,即在所有情况下都使用'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的视图的代码以及呈现它的位置。