django-ckeditor:使用内联未捕获异常

发布于 2024-10-19 18:20:39 字数 854 浏览 1 评论 0原文

我有两个简单的模型问题选择(一个问题有多个选择)。我使用内联表单集添加选择以及添加问题(通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

数理化全能战士 2024-10-26 18:20:39

我遇到了类似的问题,并在此处找到了修复程序。

这是由于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.

愿得七秒忆 2024-10-26 18:20:39

django-ckeditor 的 widgets.py 第 66 行这似乎是你的问题的根源。

从本质上讲,对 final_attr['id'] 的替换似乎是您从中获取 __prefix__ 的地方。查看框架源代码,第151行Django 的 forms/formsets.py 是该值的来源。另外,从源代码来看,在所有情况下,值似乎都会被默认前缀“form”替换,除非您以某种方式错误地使用了 _get_empty_form()

如果您提供/回答以下内容,将会很有帮助:

  1. 呈现页面后,但在“添加其他选择”之前,发布呈现的表单集(包括管理表单)中的标记属性。

  2. 您是否在代码中的任意位置直接使用 _get_empty_form()

  3. 用于创建表单集和呈现表单集的视图的代码。

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:

  1. Once your page is rendered, but before you "Add another choice", post the tag attributes from your rendered formset (incl. the management form).

  2. Are you using _get_empty_form() directly at any point in your code?

  3. Code for the view where you create the formset and where you render it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文